Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
im using turbo and want to know code according to that version

im dealing with stack that is too much cofusing because code styles are different
in every ide from turbo c borland to visual c and dev c.

i want to implement stack class that perform all basic operations

i know there are six basic operations push pop intialization of stack.check for stack full and empty before every push and pop.

pointer array will help to tell its capacity by user during program execuation but static array is fixed size method.

private memebers are int top and int *array.

i want to know there accessibility scope realted to main and other parts where ever in the program

i am trouble with constructor what it will be at intial stage

stack();

in constructor defination top is equal to -1 or 0 if from zero first pushed element will stored from index 1 otherwise from 0)

it will construct a stack object but where
in main if in main then how it will be

i want to know in turbo c what header files i should use

hoping for good reply.
Posted
Comments
Mohibur Rashid 6-Dec-11 3:16am    
So, you have nothing so far????

Do something then comeback with the specific problem.
Stefan_Lang 6-Dec-11 7:53am    
When you post a question, please do read the hints shown there, such as
- be specific
- be concise
- search the internet
Especially the latter should easily provide you with just about anything you need, and save us the trouble of digging through this heap of typos.

Yes I know, people posting here may not be native english speakers - I am not. Still, there are so many obvious typos in your question that it cannot be excused with that! You're just being lazy, and making it unnecessarily difficult for us to decipher your meaning.
P.s.: a lot of the typos wouldn't even be so bad if you put in a bit of punctuation, but even after reading over it several times, I cannot make any sense out of sentences like:

"in constructor defination top is equal to -1 or 0 if from zero first pushed element will stored from index 1 otherwise from 0)"

If all you are doing is implementing a basic stack, then you shouldn't need anything complex, and it is unlikely that you would need any header files in particular.

To emulate a stack, you need an area of memory: either an array, or a chunk of memory on the heap - I would go with the heap myself.
Assuming you are using the heap (if you use an array, then for pointer read index) you will need a base pointer to show you where it starts, a current pointer to show you where it ends, and a size value to show you how big it is.

Init:
Allocate the memory, set the two pointers to the start, set the size.
CheckEmpty:
Is Current equal to Base?
Check full:
Is Current greater than or equal to Base + Size?
Push:
If not full, put the value to the Current location, increase Current by size of value.
Pop:
If not empty, decrease Current by size of value, get value from Current location.

Done!
 
Share this answer
 
Comments
Member 8370427 6-Dec-11 5:20am    
pplease can you explain checkfull
OriginalGriff 6-Dec-11 5:27am    
If you allocate 100 bytes, and the Current value pointer is greater than or equal to the Base address plus 100, then the stack is full - any more Pushes would use unallocated memory and cause a problem.
Here you may find a C++ implementation: "Stack implementation as a class"[^].
Since stack is a general concept, you should be able to implement without problems with the compiler of your choice.
 
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