Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StackListHi
//g++ 7.4.0 #include <iostream> using namespace std; //Stack Linked List //Template code credit internet //Test driver code is created by Rezaul Hoque on February 10,2021 //Please contact at jewelmrh@yahoo.com //templated struct template <class V> class node { public: V data; node<V>* next; }; template <class T> class stack { node<T> * front,*rear; public: stack() { front =NULL; rear =NULL; } //add a node void add(T z) { node<T> *temp=new node<T>; temp->data = z; temp->next=NULL; if(isempty()) { front =temp; rear = front; } else { rear->next = temp; rear = temp; } } //link two nodes static void linkup(node<T>* x, node<T> *y) { if (x != NULL && y != NULL) { if(x->next==NULL) x->next= y; else linkup(x->next,y); } else { cout<<"Either x or y is NULL\n";} } void remove() { if(isempty()) { cout<<"is empty"; } else if (rear == front){ delete front; rear= front=NULL; } else { node<T>* temp, *temp2; temp2= rear; temp= front; while (temp->next!= NULL) { temp2= temp; temp=temp->next; } rear = temp2; rear->next=NULL; delete temp; } } bool isempty() { if (front == NULL) return true; return false; } node<T>* getfront(){ return front;} //add a node in front of a list void start(T x) { node<T> * temp = new node<T>; temp -> data = x; temp -> next = front; front = temp; } //add a node between a list void after(node<T> *q, T v) { node<T>* p = new node<T>; p->data=v; p->next=q->next; q->next = p; } void display() { node<T>* temp; temp = front; while (temp!=NULL) { cout <<temp->data<<" "; temp=temp->next; } } }; int main() { stack<char> y; y.add('i'); y.add(' '); y.after(y.getfront()->next,'!'); y.start('H'); stack<char> y1 ,y3,y2; for(int i=0;i<16;i++) { y1.add('<'); } y1.add('\n'); for(int i=0;i<16;i++) { y1.add('>'); } y1.add('\n'); y.add('T'); y.add('h'); y.add('e'); y.add('r'); y.add('e'); y.add('!'); y.add('\n'); stack<int> x,x2; y.add('F'); y.add('e'); y.add('b'); y.add(' '); x2.add(1); x2.add(0); y2.add(','); x.add(2); x.add(0); x.add(1); x.add(2); x.add(0); x.add(2); x.after(x.getfront()->next,2); x.remove (); x.remove (); x.remove (); y3.add('\n'); for(int i=0;i<16;i++) { y3.add('<'); } y3.add('\n'); for(int i=0;i<16;i++) { y3.add('>'); } y3.add('\n'); y1.display(); y.display(); x2.display(); y2.display(); x.display(); y3.display(); return 0; }
run
|
edit
|
history
|
help
0
hh
Stack with min element
On Off
Pruebas estocasticos
mergesort tree
float
Print Euler Path
VecHotel2
ThreadPool
substring search