October 2009
M T W T F S S
    Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Categories

  • [+]ASP.NET (7) 
  • [+]C# (87) 
  • [—]C++ (13) 
  • [+]Delphi (20) 
  • [+]JavaScript (24) 
  • [+]Regular Expressions (7) 
  • [+]SQL (13) 
  • [+]VB (100) 
  • [+]VB.NET (4) 

Online

Users: 7 Guests
  • Loading...


    Loading...

    Login






    Register | Lost password?

    Register





    A password will be mailed to you.
    Log in | Lost password?

    Retrieve password





    A confirmation mail will be sent to your e-mail address.
    Log in | Register
  • Stack Implementation (without graphical display)

    /* Stack Implementation (without graphical display) */
    
    #include<stdio.h>
    #include<conio.h>
    #define SIZE_OF_STACK 5
    
    struct stack
    {
     int TOP;
     int slot[SIZE_OF_STACK];
    };
    
    void push(s,item)
    struct stack *s;
    int item;
    {
    	if(s->TOP==SIZE_OF_STACK-1)
    	{
    		printf("\nERROR : Stack Overflow !");
    	}
    	else
    	{
    		(s->TOP)++;
    		s->slot[s->TOP]=item;
    		printf("\nPush Operation Successful");
    	}
    }
    
    void pop(s)
    struct stack *s;
    {
    	if(s->TOP==-1)
    	{
    		printf("\nERROR : Stack Underflow !");
    	}
    	else
    	{
    		printf("%d",s->slot[s->TOP]);
    		(s->TOP)--;
    	}
    }
    
    void peep(s,slot_number)
    struct stack s;
    int slot_number;
    {
    	slot_number--;
    	if(slot_number<0)
    	{
    		printf("\nERROR : Invalid Slot Number !");
    	}
    	else if(slot_number<SIZE_OF_STACK&&slot_number>s.TOP)
    	{
    		printf("\nERROR : Item does not exist. Topmost element is at %d !",s.TOP+1);
    	}
    	else if(slot_number>SIZE_OF_STACK-1)
    	{
    		printf("\nERROR : Slot Number beyond bounds of Stack. Stack Size is %d !",SIZE_OF_STACK);
    	}
    	else
    	{
    		printf("%d",s.slot[slot_number]);
    	}
    }
    
    void main()
    {
     struct stack s1;
     int choice,item,slot_number;
     s1.TOP=-1;
     clrscr();
     while(choice!=5)
     {
      clrscr();
      item=0;
      printf("\n ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»");
      printf("\n º          MAIN MENU           º");
      printf("\n ÌÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹");
      printf("\n º     º                        º");
      printf("\n º  1  º  Push                  º");
      printf("\n º  2  º  Pop                   º");
      printf("\n º  3  º  Peep                  º");
      printf("\n º  4  º  Display all elements  º");
      printf("\n º  5  º  Exit                  º");
      printf("\n º     º                        º");
      printf("\n ÈÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
      printf("\nEnter your choice : ");
      scanf("%d",&choice);
    
    	  switch(choice)
    	  {
    		case 1:
    			printf("\nEnter Item to be pushed : ");
    			scanf("%d",&item);
    			push(&s1,item);
    			break;
    		case 2:
    			if(s1.TOP!=-1)
    			{
    				printf("\nPopped Value is ");
    			}
    			pop(&s1);
    			break;
    		case 3:
    			printf("\nEnter Slot Number : ");
    			scanf("%d",&slot_number);
    			if(slot_number>0&&slot_number<=s1.TOP+1)
    			{
    				printf("\nPeeped value is ");
    			}
    			peep(s1,slot_number);
    			break;
    		case 4:
    			for(slot_number=1,printf("\n");slot_number<=s1.TOP+1;slot_number++)
    			{
    				 printf(" ");
    				 peep(s1,slot_number);
    			}
    			break;
    		case 5:
    			printf("\nBye Bye !");
    			break;
    		default:
    			printf("\nEnter a valid choice number (1-5) !");
    	  }
    	  getch();
     }
    
    }
    
    Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Digg
    • del.icio.us
    • Bloglines
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Technorati
    • TwitThis
    • Webnews

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

    Spam Protection by WP-SpamFree Plugin