#include<stdio.h> #include<malloc.h> struct node{ int data; struct node *link; }*top,*ptr,*start; main() { top->link=NULL; int choice,info; printf("CHOOSE AN OPTION\n"); scanf("%d",&choice); printf("1.PUSH AN ELEMENT\n"); printf("2.POP AN ELEMENT\n"); printf("3.DISPLAY\n"); printf("4.EXIT\n"); switch(choice) { case 1: printf("ENTER THE ELEMENT YOU WANT TO PUSH\n"); scanf("%d",&info); push(info); break; /*case 2: pop(top->data); break;*/ case 3: display(); break; } } push(int info) { if(top->link!=NULL) { ptr->link=top; top=malloc(sizeof(struct node)); top->data=info; top->link=NULL; } else { start->link=top; top->data=info; top->link=NULL; } } display() { ptr=start; while(ptr->link!=NULL) { int info; info=(ptr->data); printf("%d\t",info); ptr=ptr->link; } }
main
top
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)