471,084 Members | 884 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,084 software developers and data experts.

stacks-turbo C

hi, i got a prob with the new topic my teacher in data struct taught us
this afternoon. he introduced the concept of stacks. simulated how 5
elements will be pushed and popped out to the array elements and arrange
them in ascending order. but he did not show the c program for it. i
want to learn how to program it. can u help me with this please?


thanks,
kelly
Aug 2 '06 #1
2 5078
D_C
293 100+
Can you give an example?

The idea would be to put the biggest numbers on the stack first. If they aren't the biggest, pop as many off as necessary, push the new biggest number on, then push the remaining ones back on until they are ready to be popped (the smallest).
Aug 2 '06 #2
Hi,
CODE : #define STACK_SIZE 5
int top = -1; //global dec.
if (top == STACK_SIZE)/*seperate fun called push*/
{
printf("stack is full"); LOGIC
return
}
s[top++] = item;

/* write seperate fun for pop() */
if (top == -1)
{
printf("empty stack");
return;
}
printf("deleted item is %d",s[--top]);


try this one it should work.
Aug 3 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Vanessa T. | last post: by
6 posts views Thread by Sathyaish | last post: by
18 posts views Thread by pmm | last post: by
1 post views Thread by LedZep | last post: by
8 posts views Thread by cerise | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.