You are viewing a single comment's thread. Return to all comments →
using namespace std; struct node { char c; node* next; }; node* Top=NULL; node* Front=NULL; node* tail=NULL; class Solution { //Write your code here public: void pushCharacter(char c) { node *link=new node; if(Top==NULL) { link->c=c; Top=link; link->next=NULL; } else { link->c=c; link->next=Top; Top=link; }
} void enqueueCharacter(char c) { node *link=new node; if(Front==NULL) { link->c=c; Front=link; link->next=NULL; tail=Front; } else { link->c=c; tail->next=link; link->next=NULL; tail=link; } } char dequeueCharacter() { char data; node* crr=Front->next; data=Front->c; delete(Front); Front=crr; return data; } char popCharacter() { char data; node* crr=Top; data=Top->c; Top=Top->next; delete(crr); return data; }
};
Seems like cookies are disabled on this browser, please enable them to open this website
Day 18: Queues and Stacks
You are viewing a single comment's thread. Return to all comments →
using namespace std; struct node { char c; node* next; }; node* Top=NULL; node* Front=NULL; node* tail=NULL; class Solution { //Write your code here public: void pushCharacter(char c) { node *link=new node; if(Top==NULL) { link->c=c; Top=link; link->next=NULL; } else { link->c=c; link->next=Top; Top=link; }
};