![]() |
|
#1
|
|||
|
|||
logic problem?i think my logic is screwy in this function. i'm not sure if this is enough info but if more is needed then i'll give it or the files for it... the program has a stack with the items pushed in as listed below:
11 22 33 44 55 when i pop it should be taking the 11 out then the 22 then the 33, but instead it's taking the 55 out then the 44 (backwards...) and i'm pretty sure my logic is messed up in the pop function: CPP / C++ / C Code:
this is probably easy to fix, or not, but i've been staring at it for almost 2 hours and this is the only thing i have to fix and i'm done. so if anybody could possibly help... Last edited by dsmith : 09-Jul-2004 at 07:04.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#2
|
||||
|
||||
|
Quote:
Doesn't anyone read the rules? CODE Tags dang it! They are explained, defined, and requested in the stickies and the rules Now, onto the problem. All you list is what is on the stack, but not the order they were pushed. Which was last? The 55? If so, that's what's popped first. and it works. Other than that, I would need more information. __________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
|
the 11 is pushed first. i guess what's confusing me is which number would be considered the top number? the 11 since it was pushed first or the 55?
my teacher has me totally confused because he gave us a stack program and a queue program to do and i'm supposed to pop the top on both. both have the exact code except the pop functions are different. the stack program pops the 55 first (last number pushed) and the queue program pops the 11 first (first number pushed) would it help if i sent the entire code? |
|
#4
|
|||
|
|||
|
Quote:
on the other hand queues are FIFO (First In First Out) structures, since the first pushed element is also the first to pop... about your program... you could use a pointer to point to the position of the element to pop (which depends on your implementation), so that it would be the only to change between the stack and queue structures (in one case it would point to the last element pushed and in the other to the first one pushed)... |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can't find logic error | crystalattice | C++ Forum | 2 | 24-May-2004 19:31 |
| C I/O problem | kelly80 | C Programming Language | 4 | 27-Apr-2004 20:15 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 07:53 |
| problem with php5 cgi installation | fab13 | Apache Web Server Forum | 3 | 19-Nov-2003 09:11 |
| unwanted scrollbar problem | kelly001 | Web Design Forum | 3 | 24-Oct-2003 10:44 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The