Write an algorithm for the add method that will add at the end of the list instead of the beginning. What is the time complexity of this algorithm?
What will be an ideal response?
Create a new node containing a reference to the object to be placed on the stack.
Create a current pointer that references the first element of the linked list representing the stack.
Repeatedly set current to point to current.next, stopping when current.next is null. In this way, current points to the last element of the list.
Set current.next to point to the newly created node.
Increment the count of elements in the stack.
This algorithm is O(n), where n is the number of elements in the stack.
You might also like to view...
What type of monitor is composed of extremely thin panels of organic molecules sandwiched between two electrodes?
a.CRT b.LCD c.OLED d.Plasma
Heading levels in a Word outline are also known as ________ formats
Indicate whether the statement is true or false