Membalik Kata
#include <iostream.h>
#include <conio.h>
struct stack{
int top;
char kata[10];
};
stack s;
void inisialisasi()
{s.top = -1;}
void push(char data)
{s.top ++;
s.kata[s.top] = data;}
void pop()
{s.kata[s.top] = NULL;
s.top --;}
void print()
{
for (int i=s.top;i>-1;i--)
{cout<<s.kata[i];}
}
main()
{
char data[20];
int panjang_kata;
panjang_kata = strlen (data);
cout<<"Kata Awal : "<<endl;
cin>>data;
inisialisasi();
for (int i=0;i<panjang_kata;i++)
{
push(data[i]);
}
cout<<"Dibalik menjadi : "<<data ;
print();
getch();
}
Comments
Post a Comment