Question: Instructions. You are provided four skeleton program named Stack.java, Queue.java, ListNode.jana and Linked List.jam. The source files are available on Canvas in a folder named







Instructions. You are provided four skeleton program named Stack.java, Queue.java, ListNode.jana and Linked List.jam. The source files are available on Canvas in a folder named HW. Please modify the skeleton code to solve the following tasks. Task 1 (30 pts). Implement the empty(), push(int x), and pop() function for Stack in Stack.java as discussed in Lecture 5. Task 2 (30 pts). Implement the enqueue(int a), dequeue() function for Queue in Queue java as discussed in Lecture 5. Task 3 (40 pts). Implement the search(int k), insert(int a), delete() func- tion in LinkedList.java as discussed in Lecture 6. Task 4 (10 pts Extra Credit). In the push(int a) function of Stack.java, by default, we never check if the stack is already full. If we insert an element into a full stack, we should get an error. Implement the expacity check feature for push(int x). (Hint: Use System.err.println() to print the error message) Task 5 (10 pts Extra Credit). In the enqueueinte) function of Queue.java. we do not check if the quere is already full . Implement the capacity check feature for enqueueints). (Hint: Use System.err.println() to print the error message) Tisk 6 (10 pts Extra Credit). In the dequeuc() function of Queue.java, we do not check if the queue is empty. If we dequeue an empty queue we should also get an error. Implement the empty check feature for en queueint *). (Hint: Use System.err.println() to print the error message) Back LinkedList.java package ds; public class LinkedList { public ListNode head; public LinkedList () { head = null; } * Implement the LIST-SEARCH (L, k) function public ListNode search (int k) { } Implement the LIST-INSERT (L, X) function * Note that x is a integer value, not a ListNode public void insert (int x) { } Implement the LIST-DELETE(L, X) function public void delete (ListNode x) { } Convert a LinkedList to a string in the format of [#elements] public String toString() { String str; ListNode n; str = "1"; Back LinkedList.java public void delete (ListNode x) { } /* * Convert a LinkedList to a string in the format of [#elements) */ public String toString() { String str; ListNode n; str = "1"; n = this.head; while (n = null) { str += n.key + n = n.next; } str += "]"; return str; } { stub * @param args public static void main(String[] args) // TODO Auto-generated method LinkedList 1; 1 = new LinkedList(); for (int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
