New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



C program to implement a STACK


Posted Date:     Total Responses: 0    Posted By: pankaj agarwala   Member Level: Gold   Points/Cash: 6   


C program to PUSH,POP,SHOW and REVERSE a STACK



#define MAX 10
#include
#include
void push(int * stack,int*top,int no)
{
if(*top==MAX-1)
{
printf("\n OVERFLOW");
return;
}
stack[++(*top)]=no;
}
int pop(int *stack,int*top)
{
if(*top==-1)
{
printf("\n UNDERFLOW");
return -999;
}
return stack[(*top)--];
}
void show(int * stack,int *top)
{
int i;
if(*top==-1)
{
printf("\n stack Empty");
return;
}
for(i=*top;i>=0;i--)
{
printf("\n %d",stack[i]);
}
}


void reverse(int *stack,int *top)
{
int S2[MAX],t2=-1;
int S3[MAX],t3=-1;
while(*top!=-1)
push(S2,&t2,pop(stack,top));
while(t2!=-1)
push(S3,&t3,pop(S2,&t2));
while(t3!=-1)
push(stack,top,pop(S3,&t3));
}




void main()
{
int S1[MAX],t1=-1;
int ch,val;
do
{
printf("\n 1 PUSH");
printf("\n 2 POP");
printf("\n 3 SHOW");
printf("\n 4 Reverse");
printf("\n 0 EXIT");

printf("\nENter your CHoice");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\n enter Number");
scanf("%d",&val);
push(S1,&t1,val);
break;
case 2: val=pop(S1,&t1);
if(val!=-999)
printf("%d popped",val);
break;
case 3: show(S1,&t1);
break;
case 4: reverse(S1,&t1);
break;
case 0:break;
default:printf("\n Invalid choice");
}
}while(ch!=0);
getch();
}



Attachments

  • STACK (2541-30168-STACK.CPP)

  • Project Feedbacks


    No feedbacks found. Be the first to respond and make money from revenue sharing program.

    Post Feedback
    You must Sign In to post a feedback.
    Next Project: 8 CHANNEL REMOTE CONTROL USING PC PRINTER PORT
    Previous Project: To create a Calculator using C Language

    Return to Project Index

    Post New Project


    Related Projects



    Advertise Here





    Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

    ISC Technologies.
    2006 - 2009 All Rights Reserved.