Sunday, July 18, 2010

STACK


    Stack is a linear data structure which is logiacally open at one end only.Means in stack we
can insert or delete data from one end conventionally called TOP OF STACK (TOS).

We will impliment Stack in C.

Here i am writing   1)Psudo code   2) Algorithm   3) Source code in C



Implimentation of Stack in C   :-



struct stack

 {

    int arr[10];

    int tos;

  };

void push (struct stack *,int);

int pop(struct stack*);

#include < stdio.h >
#include < conio.h >
#define MAX 10

  void main()

  {

      int x,ch;

      struct stack s;

      s.tos=-1;

     

  do{
      printf("\n enter ur choice \n 1)for push an element \n 2)pop an element \n 3)for exit");

      scanf("%d".&ch);

      switch(ch)

        case 1:

                    printf("enter the number to be pushed in stack");

                    scanf("%d".&x);

                    push(&s,x);

                    break;

        case 2:

                    x=pop(&s);

                    printf("popped element is = %d",x);

                    break;

        case 3:

                    exit;
          printf("do you want to continue Y/N);
          scanf("%c",&choice);
          } while(choice=='y');

     getch();
  }


for more information about STACK i would like to recommend NPTEL video from IIT Delhi by Dr. NAVEEN GARG.




 Wait for my next post for Psudo code, algorithm and source code of function "push" & "pop".

No comments:

Post a Comment