Implementation of Stack with Singly Linked List : C Program
Here is the code for implementation of stack with singly linked list : program code : #include<stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; struct node *top=NULL; void push(int d) { struct node *newnode=(struct node*)malloc(sizeof(struct node)); newnode->data=d; newnode->next=NULL; if(top==NULL) { top=newnode; } else{ newnode->next=top; top=newnode; } printf("\ndata %d has been pushed (entered to stack).",d); } void pop() { struct node *p,*temp=top; if(temp=NULL) { printf("\nstack is empty."); return; } p=top; top=top->next; free(p); ...