473,624 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stacks-turbo C

1 New Member
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 5197
D_C
293 Contributor
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
Ashok P
3 New Member
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
2610
by: Vanessa T. | last post by:
Hello All! Is there a place where I can learn stacks, (push and pop) etc. Thanks,
4
3199
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 structures we've studied (ofcourse in c++). For e.g. implementations of a stack could be paranthesis matching/evaluating polish notation etc. Can anyone suggest implementations/usage of the above mentioned data
6
1674
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
1566
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
1196
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 punctuation. I have to somehow take the input from the txtbox, stack it letter by letter onto a stack, then display it written forward and below it written backwards. I understand the concept of stacks -- I just need a little push in the right...
10
2119
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 to the application world. We may wait for a suitable popular resolution and jump to that version in the future. There's already a rift between PHP4 and PHP5, and then further developments such as these create another, splitting the camp into 4....
2
4574
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 when it has to increase its memory. http://www.sgi.com/tech/stl/stack.html, the stacks default underlying container is a deque that has amortized constant time insertion and removal of elements.
0
2327
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> #include<conio.h> int top; int bot; void main() {
14
1529
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 print them on a ream of 8.5 by 11 or 14 stock and take them to the office store for later cutting. It would be nice if the paper cutter could produce your finished product - say 4, 8, 12 or more individual stacks of cards, rubber banded &...
8
3925
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 clubs. I use objects as my cards. I don't know how to make more than one stack. Can anyone help me out? If I'm not being clear, I'll be happy to clarify the problem I have. here is the class I used to make the Objects for cards, public class...
0
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8679
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.