C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2009, 04:28 PM   #1
Registered User
 
Join Date: Sep 2009
Posts: 13
top of stack

This may seem simple, but how should I assign a variable "d" to the top of a stack for use in comparing a string variable to the variable at the top of the stack?
greatunknown is offline   Reply With Quote
Old 10-27-2009, 04:34 PM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,642
Keep a pointer to the the top of the stack. It depends on how you are implementing it. You'll need to be more specific. By 'top' do you mean the last thing you have pushed, or the first thing?


Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 10-27-2009, 04:45 PM   #3
Registered User
 
Join Date: Sep 2009
Posts: 13
so i have an empty stack, i need "char d" to be assigned to the top of the stack, meaning the last thing pushed, in order to compare it with something else without having to pop the stack and then compare

how should char "d" be assigned?
greatunknown is offline   Reply With Quote
Old 10-27-2009, 04:54 PM   #4
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,642
You could write a peek function that returns the last item entered into the stack, without actually removing it. But if you're going to try to compare multiple items, or chains of items, I don't know that a stack is really what you want. Generally you just push whatever you want on the stack, and then you pop the top on and compare it.
Code:
type peek( stack *s )
{
    return s->top;
}

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixing my program Mcwaffle C Programming 5 11-05-2008 03:55 AM
stack and pointer problem ramaadhitia C Programming 2 09-11-2006 11:41 PM
Question about a stack using array of pointers Ricochet C++ Programming 6 11-17-2003 10:12 PM
error trying to compile stack program KristTlove C++ Programming 2 11-03-2003 06:27 PM
Stack Program Here Troll_King C Programming 7 10-15-2001 05:36 PM


All times are GMT -6. The time now is 11:46 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22