The following is a Java method that is part of a Linked List
based Stack implementation:
void foo() {
if (front==null) return;
LinkedNode c = front;
int a = count/2;
for (int i=1; i<a; i++)
c = c.next;
c.next = null;
}
Describe what this method is doing at a high level.
|
Removing the last element |
||
|
Removing the upper half of elements in the Stack. |
||
|
Removing the first element |
||
|
Removing the bottom half of elements in the Stack. |
Solution in BOLD:
Java code explanation:
void foo() {
if (front==null) /*Checks if the root is NULL
or not*/
return; /* If List is empty return
*/
LinkedNode c = front; /*Take the front node of the
list*/
int a = count/2; /*Divide the node's count by 2 to find the middle node*/
for (int i=1; i<a; i++) /*Traverse the
list until middle node*/
c =
c.next;
/*Move the pointer to next node*/
c.next = null; /*Make the node as NULL to Delete the mid-node..*/
} #end_of_foo
----------------------------------------------------------------------------
Solution:
The Sample Linked list based stack implementation is as follows.
Top node - | 24 |
| 14 |
| 05 | UPPER-HALF ELEMENTS
| 72 | <---------------------------------------------------->
| 96 | BOTTOM-HALF ELEMENTS
| 45 |
Front node | 12 |
-------------------------------------------------------------------------------
Since the list (stack) is traversed from the front to top node,
this method is removing "Removing the
upper half of elements in the Stack".
Traversing up to the middle node(72) and making its next node as NULL, will remove the remaining nodes.
-------------------------------------------------------------------------------
The following is a Java method that is part of a Linked List based Stack implementation:...
(JAVA)Define a method getFrequency(anEntry) for the Linked List implementation of stack ADT. The method returns the number of occurrences of anEntry in the stack.
Parts B is about our linked list implementation. avvut our linked list implementation. Recall that the declaration of a list node is. class DListNode { public int key; public DistNode previous; public DListNode next; de ollos Salon You can assume that this is an inner class within the full MyLinked List class. B. Write a method that will add a new element to the front of a doubly linked list. Assume that head and tail point to the head and...
Create a Java code that includes all the methods from the
Lecture slides following the ADTs
LECTURE SLIDES
Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....
There is a data structure called a drop-out stack that behaves like a stack in every respect except that if the stack size is n, then when the n+1element is pushed, the bottom element is lost. Implement a drop-out stack using links, by modifying the LinkedStack code. (size, n, is provided by the constructor. Request: Please create a separate driver class, in a different file, that tests on different types of entries and show result of the tests done on...
Convert following code to implement linked list C++ language #include<iostream> using namespace std; int top = -1; //globally defining the value of top, as the stack is empty void push(int stack[], int x, int n) { if (top == -1) //if top position is the last of posiition of stack,means stack is full { cout << "Stack is full Overflow condition"; } else { top = top + 1; //incrementing top position stack[top] = x; //inserting element on incremented position...
Complete the implementation of the LinkedStack class presented in Chapter 13. Specifically, complete the implementations of the peek, isEmpty, size, and toString methods. See Base_A06Q1.java for a starting place and a description of these methods. Here is the base given: /** * Write a description of the program here. * * @author Lewis et al., (your name) * @version (program version) */ import java.util.Iterator; public class Base_A06Q1 { /** * Program entry point for stack testing. * @param args Argument...
Java help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements DoubleEndedList { private Node front; // first node in list private Node rear; // last node in list private int size; // number of elements in list ////////////////////////////////////////////////// // YOU MUST IMPLEMENT THE LOCATE METHOD BELOW // ////////////////////////////////////////////////// /** * Returns the position of the node containing the given value, where * the front node is at position zero and the rear node is...
Assume you are working with a stack implementation of the linked list definition pasted below, write a member method “pop”. The method should return a value (in the “popped” node). Assume the existence of the node references called “TheStack” and “Top”. These references point to the start (or bottom) and top of the stack (or back of the list). ------- Definition: class node { boolean data; node link; }
Doubly Linked List Java Help Details: First, read the DoublyLinkedList.java code and try to understand what each field stores and what each method is doing. Modify and complete the class as described below •The field size was defined in the class but was never maintained. Set the current default value and modify it whenever it is needed in the existing methods and other methods you implement as it is needed. It should always include the number of Nodes inside the...
*********************Java recursion********************** Plz help me write a method in java that traverse Through a integer linked list recursively . The method returns a string with every element in the list and a space in between each element in reverse order. THE METHOD DOES NOT REVERSE THE LINKED LIST. IT JUST RETURNS A STRING CONTAINING THE ELEMENTS OF THE LIST IN REVERSE ORDER. ASSUME ALL THE ELEMENTS IN THE LINKED LIST ARE int... method signature is something like : public String...