New Member FAQ | Forums | Earn Revenue | Posting Guidelines | Help Topics


ResourcesPractice TestsAsk ExpertsQuestion PapersJobsStudy in UKUniversitiesCollegesCoursesSchoolsTraining


My Profile

Awards & Gifts


Active Members
TodayLast 7 Daysmore...





C program to implement a STACK


Posted Date:     Total Responses: 0    Posted By: pankaj agarwala   Member Level: Silver   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

    Author: Member Level: BronzeRevenue Score: 1 out of 5
    good attempt


    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

    Subscribe to Email
  • Get Jobs by Email
  • Forum posts by Email
  • Articles by Email



  • website counter

    Online Membersbenson gomez
    Ashish Kumar
    Iti Tyagi
    Sakshi Sood
    Munish kumar
    dks
    Arvind
    siva
    sathishkumar
    Ramakrishna Kambhampati
    Shiyas
    More...



    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    AdSense Revenue Sharing sites   Advertise   Talk to Tony John
    ISC Technologies, Kochi - India
    2006 - 2012 All Rights Reserved.