Docstoc

pro4

Document Sample
pro4 Powered By Docstoc
					#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
struct linked
{
      int data;
      struct linked *next;
};
typedef struct linked stack;
stack*top=0;
int size=sizeof(stack);
int push();
int pop();
int display();
void main()
{
      int ch;
      clrscr();
      while(1)
      {
            printf("\n\t\t~~STACK IMPLEMENTATION USING LINKED LIST~~");
            printf("\n\t1.PUSH");
            printf("\n\t2.POP");
            printf("\n\t3.DISPLAY");
            printf("\n\t4.EXIT");
            printf("\n\tEnter your choice-->");
            scanf("%d",&ch);
            switch(ch)
            {
            case 1:
                  push();
                  break;
            case 2:
                  pop();
                  break;
            case 3:
                  display();
                  break;
            case 4:
                  exit(1);
            default:
                  printf("wrong choice\n");
            }
      }
}
int push(stack*new)
{
      new=(stack*)malloc(sizeof(stack));
      printf("\nEnter the element to be pushed-->");
      scanf("%d",&new->data);
      new->next=top;
      top=new;
      return(0);
}
int pop(stack*temp)
{
      if(top==0)
            printf("\nSTACK IS UNDERFLOW");
      else
      {
            temp=top;
            top=top->next;
            printf("Deleted element is %d",temp->data);
            free(temp);
      }
      return(0);
}
int display(stack*p)
{
      p=top;
      if(p==0)
            printf("\n The stack is empty");
      else
            printf("\nthe Elements in the stack-->");
      {
            do
            {
                  printf("\n%d",p->data);
                  p=p->next;
            }while(p!=0);
      }
      return(0);
}

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:1
posted:10/18/2012
language:Latin
pages:2