| · Portal |
Help
Search
Members
Calendar
|
| Welcome Guest ( Log In | Register ) | Resend Validation Email |
![]() ![]() ![]() |
| Ron |
|
||||
|
Administrator Group: Admin Posts: 54 Member No.: 1 Joined: 2-February 06 |
This was part of the last assignment for Data Structures. The due date has passed, and Dr. Hao doesn't accept late homework, so it should be safe to discuss now. I can usually get my programs to work, but often find that after I'm done that I've gone the long way around. I'm wondering if I've done that again this time. Please check out my code and tell me what you think. The assignment involved a stack created by the following:
Then among other things, we were to pick out the bottom element on the stack and assign it to a variable, leaving the stack unchanged. My solution was to pop the stack elements to an array, copy the variable, then push them all back.
SIZE is a constant. empty checks to see if the stack is empty. pop pops the top element off the stack. push puts one item back on the stack. So what do you think? Any suggestions or comments? Thanks. PS. I'm sorry to say the [code][/code] blocks are quite what I'd hoped they be. They don't keep the color of the text, but hopefully still allow some degree of readability. |
||||
| The Tony |
Posted: Feb 10 2006, 08:55 PM
|
||||
|
Newbie Group: Members Posts: 6 Member No.: 7 Joined: 9-February 06 |
First off thank you, Ron for the readible code second this may be a little late because he went over it class but i did it about the same; but instead of an array i used a secondary stack they use the same memory but im pretty sure the overhead of using a stack is a bit more than an array with that said the use of an alternative stack is a more dynamic (memory saving) way of solving this problem because stack are very verstile, but only if they are beign used multiple times. In this case it really dosnt matter. The final consideration is a counter varible vs a temp varible to push back on the second stack. i think your soltion is best for the reason that you dont pick up a
your code goes straight to the push.
|
||||
| Ron |
Posted: Feb 11 2006, 01:27 AM
|
|
Administrator Group: Admin Posts: 54 Member No.: 1 Joined: 2-February 06 |
Thanks for the feedback.
|
| JuanSauceda |
Posted: Sep 9 2007, 11:40 PM
|
|
Advanced Member Group: Admin Posts: 48 Member No.: 3 Joined: 4-February 06 |
Welcome back CSA!
|
![]() |
![]() ![]() ![]() |