#include <iostream>
#include <string.h>
using namespace std;
struct Node
{
string data;
Node* pNext;
};
struct Stack
{
Node* pTop;
};
Node* CreateNode(string x)
{
Node* p = new Node;
if (p == NULL)
exit(1);
else
{
p->data = x;
p->pNext = NULL;
}
return p;
}
void CreateStack(Stack& s)
{
s.pTop = NULL;
}
bool isEmpty(Stack s)
{
if (s.pTop == NULL)
return true;
else
return false;
}
void Push(Stack& s,Node*p)
{
if (isEmpty(s) == true)
s.pTop = p;
else
{
p->pNext = s.pTop;
s.pTop = p;
}
}
void Pop(Stack& s,string &x)
{
if(s.pTop == NULL)
cout<<"Stack Underflow"<<endl;
else
{
cout<<s.pTop->data <<endl;
s.pTop = s.pTop->pNext;
}
}
void reverseString(Stack &s,Node *p,string str)
{
int i = str.length(),j;
p = s.pTop;
while(p != NULL)
{
if(p->data[i] == ' ' && i != 0)
{
j = i + 1;
while(p->data[j] != ' ' && p->data[j] != '\0')
{
cout << p->data[j];
j++;
}
cout << " ";
}
else if(i == 0)
{
j = i;
while(p->data[j] != ' ')
{
cout << p->data[j];
j++;
}
}
i--;
}
}
int main()
{
Stack s;
CreateStack(s);
string str;
getline(cin, str);
Node *p = CreateNode(str);
Push(s,p);
reverseString(s,p,str);
Pop(s,str);
return 0;
}
Code em đây ạ, nhưng mà khi chạy ra ouput thì nó báo lỗi gì ấy ạ