Question: public class DynamicList { private DynamicNode list; public void print() { DynamicNode temp = list; while(temp != null) { System.out.print(temp.info); temp = temp.next; } //

public class DynamicList {

private DynamicNode list;

public void print() {

DynamicNode temp = list;

while(temp != null) {

System.out.print(temp.info);

temp = temp.next;

} // is this correct?

}

public void reverseIteratively() {

DynamicNode current = list;

DynamicNode nextNode = null;

DynamicNode prevNode = null;

while(current!= null) {

nextNode = current.next;

current.next = prevNode;

prevNode = current;

current = nextNode;

}

list = prevNode;

// is this correct?

}

public void Concat(DynamicList x) {

}

public int SumList() {

return 0;

}

public void union(DynamicList x) {

}

public void intersection(DynamicList x) {

}

public void deleteEverySecond() {

}

public DynamicList() {

list = null;

}

public boolean isEmpty() {

return list == null;

}

public void insertFirst(Object x) {

DynamicNode q = new DynamicNode(x, null);

if (!isEmpty())

q.setNext(list);

list = q;

}

public void insertAfter(DynamicNode p, Object x) {

if (p == null) {

System.out.println("void insertion");

System.exit(1);

}

DynamicNode q = new DynamicNode(x, p.getNext());

p.setNext(q);

}

public Object deleteFirst() {

if (isEmpty()) {

System.out.println("void deletetion");

System.exit(1);

}

Object temp = list.getInfo();

if (list.getNext() == null)

list = null;

else

list = list.getNext();

return temp;

}

public Object deleteAfter(DynamicNode p) {

if (p == null || p.getNext() == null) {

System.out.println("void deletion");

System.exit(1);

}

DynamicNode q = p.getNext();

Object temp = q.getInfo();

p.setNext(q.getNext());

return temp;

}

public void place(Sortable x) {

DynamicNode p, q = null;

for (p = list; p != null && x.compareTo(p.getInfo()) > 0; p = p.getNext())

q = p;

if (q == null)

insertFirst(x);

else

insertAfter(q, x);

}

public void insertLast(Object x) {

DynamicNode p = new DynamicNode(x, null);

DynamicNode q = null;

if (isEmpty())

list = p;

else {

for (q = list; q.getNext() != null; q = q.getNext())

;

q.setNext(p);

}

}

public DynamicNode search(Object x) {

DynamicNode p;

for (p = list; p != null; p = p.getNext())

if (p.getInfo().equals(x))

return p;

return null;

} // end search

public void removeX(Object x) {

DynamicNode p = list, q = null;

while (p != null) {

if (p.getInfo().equals(x)) {

p = p.getNext();

if (q == null)

deleteFirst();

else

deleteAfter(q);

} else {

// advance to the next node in the list

q = p;

p = p.getNext();

}

} // end while

}// end removex

} // end dynamic list

public class DynamicList { private DynamicNode list; public void print() { DynamicNodetemp = list; while(temp != null) { System.out.print(temp.info); temp = temp.next; }

public class Dynamiclist private DynamicNode list; public Dyhamiclist() 5 list null; public boolean isEmpty) return list == null; public void insertFirst (Object x) { DynamicNode q = new DynamicNode(x, null); if (!isEmpty)) q. setNext(list); list = q; public void insertAfter(DynamicNode p, object x) { if (p-null) { System.out.println("void insertion"); System.exit(1); DynamicNode q p. setNext (g); new DynamicNode(x, p.getNext()); public object deleteFirst() if (isEmpty)) [ System.out.println("void deletetion"); System.exit(1); Object temp = list. getInfo(); if (list , getNext() == null) list = null; else list list. getNext(); = return temp; public Object deleteAfter(DynamicNode p) { if (p-null II p.getNext() == null) { System.out.println("void deletion"); System.exit(1); public class Dynamiclist private DynamicNode list; public Dyhamiclist() 5 list null; public boolean isEmpty) return list == null; public void insertFirst (Object x) { DynamicNode q = new DynamicNode(x, null); if (!isEmpty)) q. setNext(list); list = q; public void insertAfter(DynamicNode p, object x) { if (p-null) { System.out.println("void insertion"); System.exit(1); DynamicNode q p. setNext (g); new DynamicNode(x, p.getNext()); public object deleteFirst() if (isEmpty)) [ System.out.println("void deletetion"); System.exit(1); Object temp = list. getInfo(); if (list , getNext() == null) list = null; else list list. getNext(); = return temp; public Object deleteAfter(DynamicNode p) { if (p-null II p.getNext() == null) { System.out.println("void deletion"); System.exit(1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!