STACKS LINKEDLIST

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; struct node{ int value; struct node* next; }; class Stack { struct node *top; public: Stack() { top = NULL; } void push(int value) { struct node *temp = new struct node; if(top==NULL) { temp->value = value; temp->next = NULL; top = temp; } else { temp->value = value; temp->next = top; top = temp; } } int pop() { int value = top->value; struct node *temp = top; top = top->next; free(temp); return value; } int peek() { return top->value; } }; int main() { Stack s1; s1.push(5); s1.push(6); s1.push(7); cout<<s1.pop()<<"\n"; cout<<s1.peek()<<"\n"; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines