Question: //doubly linked list remove left node(popLeft), remove right node (popRight) and return popped elements: public class MyDeque { Node first = null; Node last =
//doubly linked list remove left node(popLeft), remove right node (popRight) and return popped elements:
public class MyDeque {
Node first = null; Node last = null; int N = 0; //initializes an empty queue here static class Node { public Node() { } public int item; public Node next; public Node prev; }
public boolean isEmpty () { //simply return 0 when empty //if (N==0) //already what is being tested for; return (N==0) ; //empty when N=0;//remember this is giving us true || false; } public int size () { return N; }
public int popLeft () { //Need help here not working Node temp= first; if(first != null) {//when first is not null if(first.next==null) {//all list empty case last=null; first=null; } else { first.next.prev= null; first=first.next; } } return temp.item;
}
//Help appreciated
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
