actually I had a problem to reverse my string using stack.. can anyone help me? this is a sample of my code :
#include<iostream>
#include<stdlib.h>
using namespace std;
void push();
void display();
void pop();
struct words
{
char data [20];
struct words *next;
};
words *head;
main()
{
int i;
cout<<"enter your alphabet :"<<endl;
for (i=0; i<4; i++)
{
push();
}
display();
pop();
}
void push()
{
words *newptr;
newptr= new words;
//cout<<"masukkan perkataan";
cin>>newptr->data;
newptr->next=NULL;
newptr->next=head;
head=newptr;
}
void display()
{
words *p;
p=head;
while (p !=NULL)
{
cout<<p->data;
p=p->next;
}
cout<<endl;
}
void pop()
{
words *currentnode;
currentnode=head;
if (head !=NULL)
{
head=head->next;
}
else
{
cout<< "no data is found";
}
free (currentnode);
}