Question

You implemented a stack as a singly linked list (you add at the head and remove...

You implemented a stack as a singly linked list (you add at the head and remove from the head). Perform the following operations on
the stack: push(50), push(90), push(30), push(53), push(52), pop(), push(51), pop(), pop(), push(100), and push(15).
After all the operations are performed, draw the resulting linked list. Indicate which node is the top of the stack in the resulting linked
list.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
push(50)    top -> [50]
push(90)    top -> [90] -> [50]
push(30)    top -> [30] -> [90] -> [50]
push(53)    top -> [53] -> [30] -> [90] -> [50]
push(52)    top -> [52] -> [53] -> [30] -> [90] -> [50]
pop()       top -> [53] -> [30] -> [90] -> [50]
push(51)    top -> [51] -> [53] -> [30] -> [90] -> [50]
pop()       top -> [53] -> [30] -> [90] -> [50]
pop()       top -> [30] -> [90] -> [50]
push(100)   top -> [100] -> [30] -> [90] -> [50]
push(15)    top -> [15] -> [100] -> [30] -> [90] -> [50]

Answer:
---------
value of the stack is top -> [15] -> [100] -> [30] -> [90] -> [50]
with 15 at the top of the stack.
Add a comment
Know the answer?
Add Answer to:
You implemented a stack as a singly linked list (you add at the head and remove...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas....

    I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas. public class Node ! int id; Node next: public Node (int id) ( this.id id: Write program codes for the traditional: 1) append int id), prepend(int id), removeFirstNodeO. displayAlINodesO, and findById(int id) operations for a singly linked list 2) pushint id), pop), peek0, displayAllNodes0 operations for a stack 3) enQueue(int id), deQueuel), displayAINodes() operations for a gueue Please make sure that you declare separate...

  • Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the...

    Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list. Node prev = head; Node curr = head. next; while(curr.next!=null) { if(prev.element > 3) { prev = curr; curr = curr.next; } else break; } head = prev.next; Question 3 options: 3 2 4 1...

  • How do you implement a stack using a singly linked list in Java? Can you make...

    How do you implement a stack using a singly linked list in Java? Can you make it a simple implementation with just push and pop methods.

  • In C++, a stack can be implemented using either an array or a singly linked list,...

    In C++, a stack can be implemented using either an array or a singly linked list, either approach may be appropriate. But one may be better than the other one. Indicate 2 advantages of each approach has over the other.

  • 1. The Operand Stack - opstack The operand stack should be implemented as a Python list....

    1. The Operand Stack - opstack The operand stack should be implemented as a Python list. The list will contain Python integers, strings, and later in Part 2 code arrays. Python integers and lists on the stack represent Postscript integer constants and array constants. Python strings which start with a slash / on the stack represent names of Postscript variables. When using a list as a stack, assume that the top of the stack is the end of the list...

  • Derive a class called Stack from the linked list described in Assignment 2 (list of Dates)....

    Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...

  • 1.If a list is implemented as a singly linked stack, give the big-O worst-case time complexity...

    1.If a list is implemented as a singly linked stack, give the big-O worst-case time complexity of the following operations (as usual use the smallest standard big-O category that works: a) push_front, b) push_back, c) lookup, d) read the i'th member 2.Repeat question 3 for a dynamic array (for example, as in the C++ vector class)

  • implementing the stack ADT with singly linked list Theoretical Questions, pot - Adobe Acrobat Reader DC...

    implementing the stack ADT with singly linked list Theoretical Questions, pot - Adobe Acrobat Reader DC File Edit View Sign Window Help Home Tools Theoretical Questio. * Sign In B6Q 0 175 20 } Search Reduce S70 } } Do Export PDF Adobe Export PDF Convert PDF Files to word Ortel Online Select Postile Theoretical..cons.pdt X Microsoft Word docu Programming Part (preferably using Java): 4. (75 marks) Implement the stack ADT with singly linked list (without using classes from any...

  • When using a linked list for stack implementation, we use the first Node as the top...

    When using a linked list for stack implementation, we use the first Node as the top entry of stack. Explain, in this linked list implementation, how we add and how we remove an entry from a stack. Use linked nodes diagrams to save your time. add remove

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT