473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 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 5181
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

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

Similar topics

5
by: Vanessa T. | last post by:
Hello All! Is there a place where I can learn stacks, (push and pop) etc. Thanks,
4
by: Ice | last post by:
Hi there, I'm not sure if this is the right group for this- If it isn't, could anyone point me in the right direction? For our data structures exam, we are usually asked to implement the...
6
by: Sathyaish | last post by:
I've searched Google and found a few, but I am not so satisfied. Any good reading on "stacks and heaps" about how and when memory is allocated from the heap?
18
by: pmm | last post by:
Hi all, Plz dont fire at me if this is a silly question Is there any way to know in which direction stack grows pmm
1
by: LedZep | last post by:
This program has to use a stack to determine whether a string is a palindrome (a string that is spelled identically backward and forward). The program has to ignore spaces, case sensitivity and...
10
by: Rich Kucera | last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version configurations inevitable Will have to wait to see what the impact of problems such as http://bugs.php.net/bug.php?id=33643 ...
2
by: Daniel | last post by:
Hi, I have a question regarding the memory managment in stl stacks. I want to use stacks to store a very large amount of numbers (some millions), thus I'm interested in how the stack behaves...
0
by: raghuveer | last post by:
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have #include<stdio.h>...
14
by: MLH | last post by:
Suppose you needed to print a large number of consecutively numbered documents the size of a post-card ==or perhaps even a business card using a laser printer and 60# bond. Suppose you planned to...
8
by: cerise | last post by:
I can't figure out how to make and handle multiple stacks and use them so I could create four linked list stacks representing each suit of cards, one stack each for diamonds, hearts, spades, and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.