Open Suraj-Ajjampur opened 5 months ago
struct Node{ int data; struct Node *next; }
Empty Condition
If Top points to NULL
Full Condition
If heap is full i.e if malloc fails and assigned pointer is NULL
void push(int x) { Node *t =(struct Node*)malloc(sizeof(struct Node)); if(t == NULL) printf("Stack Overflow"); else { t->data=x; t->next=top; top=t; } }
int pop() { struct Node *t; int x=-1; if(top==NULL) printf("Stack is Empty\n"); else { t=top; top=top->next; x=t->data; free(t); } return x; }
Initial code in commit https://github.com/Suraj-Ajjampur/DSA/commit/6c471508c62f5f0a0b9651202f05ef75eb407e79
Structure
Empty Condition
If Top points to NULL
Full Condition
If heap is full i.e if malloc fails and assigned pointer is NULL
Push Inserting an element in the stack
Pop