Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi friends,

I want to implement a stack with an array please help me !! (é_è)

thank you
Posted

This GeeksPlanet article[^] might help.
 
Share this answer
 
Comments
pablo ramos1 20-Sep-11 14:19pm    
Think you André Kraak, but i want a struct contain a table T[10] and a int Top...
Sergey Alexandrovich Kryukov 20-Sep-11 16:57pm    
To the point, my 5.
Though, it's not helping OP who is writing gibberish like "T[10]" instead of reading the article.
--SA
André Kraak 20-Sep-11 17:01pm    
Thanks, it is appreciated.
Chuck O'Toole 20-Sep-11 19:08pm    
Just a comment on the article you pointed to, I don't think that's a very good article. It really doesn't instruct, it only works because of the double dimension of the 'stack' to hold up to 15 characters per entry, uses strcpy, etc. While it works for the author's specific need / example, it will confuse people looking for a simple stack implementation. But, here's 5 for finding it for the OP.
Back when I was in college, before hardware stacks were invented (and before C was invented), a stack implementation was simply.

Init: declare dimension stack[100] (set the max size of the stack)
integer current = 0;

Push: stack[current++] = data_to_be_saved

Pop: data_restored = stack[--current]

Getting the type right, converting from pseudo-C to real C/C++, and handling cases where the data is an object or string or entire struct are exercises for the student.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900