Assign values of a stack to another stack


I am working on this assignment.

I need to create a temporary stack without initializing it.

Then push the items of stack 1 into this temporary stack using a while loop.

Then I need to use another (nested?) loop to walk through the temp stack and add the items from temp stack onto stack 2.

Then I need to set stack 1 and 2 equal so stack 2 remains unchanged.


Your interfaces look a bit off. Let's start there and see if that gets you over your hump.

stack.top() usually peeks at an item, but doesn't remove it. This doesn't seem useful for transfering from one stack to anther. You already have isEmptyStack() to check that the top element exists.

stack.pop() usually takes the top item from a stack. This sounds useful for transferring.

stack.push(item) places item onto the top of the stack. This sounds useful for transferring.

stack.push() just seems wrong. Push what?

Hopefully, once you implement these methods, the rest will start to make sense from the english description of the problem you provided.

Update: this is what you want:

|a | | | | | | | | | |c | |b | | |b | | | |b | | |b | |c | | |c |a | |c |a | | |a | 1 tmp 2 1 tmp 2 1 tmp 2 1 tmp 2 | | | | | | | | |a | |b | | | |b | | |b | |a |c | |a |c | | |c 1 tmp 2 1 tmp 2 1 tmp 2

Now, with just push, pop, and IsEmptyStack, with no assigning of stacks to one another (that sort of defeats the purpose of the assignment), can you do this?


  • Why does a Flume source need to recognize the format of the message?
  • How to pass information between Activities
  • What audio format Spotify uses and how they transfer the files to mobile devices?
  • Add an item into a list recursively
  • Example Oozie job works from Hue, but not from command line: SparkMain not found
  • Passing value from Servlet to JSF Action method in WebLogic
  • ArrayList in C#
  • How does “boxing” work in .NET?
  • jquery limit lines in a paragraph and apply three periods to the end
  • xul/xpcom copy image from string to clipboard
  • JS object key sequence
  • How to control Trigger state (Pause, Play) using code (not just buttons)
  • reduce/reduce conflicts using ocamlyacc
  • How to write string.Contains(someText) in expression Tree
  • How to get the index of element in the List in c#
  • How to replace TouchesBegan with UIGestureRecognizer
  • Rails AREL .where statement
  • How to get Fully qualified domain name in unix
  • How to remove a SwiftyJSON element?
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • With Hadoop, can I create a tasktracker on a machine that isn't running a datanode?
  • Allowing both email and username for authentication
  • Get one-time binding to work for ng-if
  • Regex thinks I'm nesting, but I'm not
  • What is the “return” in scheme?
  • Can Jackson SerializationFeature be overridden per field or class?
  • How do you troubleshoot character encoding problems?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to disable jQuery.jplayer autoplay?
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • python regex in pyparsing
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Android Google Maps API OnLocationChanged only called once
  • Qt: Run a script BEFORE make
  • Django query for large number of relationships
  • reshape alternating columns in less time and using less memory
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • How can I use threading to 'tick' a timer to be accessed by other threads?