Menu

Need Code Given Use Linked List Given Make Stack Queue Need Use Generics Linked List Code Q43869924

I need the code given to use the linked list given and to make astack and queue. All need to use generics.

Linked List code:

public class List {
   // put all fields from ListAsLinkedList classhere
   Node cur;
   Node head;
   Node tail;
   int size = 0;
  
   // put all methods from ListAsLinkedList classhere
   // Adds the characters to the end of the list
    public void append(char value) {
       if (head == null) {
           cur = newNode();
          cur.setData(value);
           head = tail =cur;
       } else {
           cur =tail;
           Node temp = newNode();
          cur.setNext(temp);
           cur =cur.getNext();
           tail =cur;
          tail.setData(value);
       }
       size += 1;
   }
          
   // Adds the characters to the front of the list
   public void prepend(char value) {
       if (head == null) {
           cur = newNode();
          cur.setData(value);
          System.out.println(cur);
           head = tail =cur;
          System.out.println(head);
          System.out.println(cur);
       } else {
           Node temp = newNode();
          temp.setNext(head);
           head = cur =temp;
          head.setData(value);
       }
       size += 1;
   }

   // Deletes values at a certain position
   public void deleteAt(int position) {
       cur = head;
       if (position < size) {
           for(int i = 1; i< position; i++) {
              cur = cur.getNext();
           }
          cur.setNext(cur.getNext().getNext());
       } else {
           while(cur.getNext() != tail) {
              cur = cur.getNext();
           }
           tail =cur;
          cur.setNext(cur.getNext().getNext());
       }
   }

   // Gets the size of the list
   public int size() {
       int count = 0;
       cur = head;
       while (cur != null) {
           cur =cur.getNext();
           count++;
       }
       return count;
   }

   // Finds the value at a certain position
   public char getValueAt(int position) {
       cur = head;
       for (int i = 0; i < position;i++) {
           cur =cur.getNext();
       }
       return cur.getData();
   }
  
   // Finds the position of a certain value
   public int positionOf(char value) {
       cur = head;
       int position = 0;
       while (cur.getNext() != null){
           if(cur.getData()== value)
              return position;
           cur =cur.getNext();
           position +=1;
       }
       return -1;
   }
}

/** A linked list node for our linked list */
class Node {
   // put all fields from Node class here
   private char data;
   private Node next;
  
   // put all methods from Node class here
   // Sets the node
   public Node() {
       data = 0;
       next = null;
   }

   // Gets the value or character from the node
   public char getData() {
       return data;
   }

   // Gets the next node in the list
   public Node getNext() {
       return next;
   }

   // Sets the data
   public void setData(char data) {
       this.data = data;
   }

   // Sets what is linked next
   public void setNext(Node next) {
       this.next = next;
   }

}

Stack code given:

public class Stack {
/** List objects to hold our stack items.
      Use List operations to implement themethods below */
private List list;

public Stack() {
    // instantiate list here

}

public void push(char value) {

}

public char pop() {

}

public char peek() {

}

public boolean isEmpty() {

}
}

Queue code given:

public class Queue {
/** List objects to hold our queue items.
      Use List operations to implement themethods below */
private List list;

public Queue() {
    // instantiate list here
  

}

public void enqueue(char value) {
  

}

public char dequeue() {

}

public char front() {

}

public boolean isEmpty() {

}
}

Each are in seperate codes and are called another code I just needthese three codes working.

Expert Answer


Answer to I need the code given to use the linked list given and to make a stack and queue. All need to use generics. Linked List …

OR