Question
-------------------- IntLinkList : public class IntLinkList { private IntNode top; //The reference to the first Node //=========== Solution code ============================= public IntLinkList(int[] data){ for (int
--------------------
IntLinkList :
public class IntLinkList { private IntNode top; //The reference to the first Node //=========== Solution code ============================= public IntLinkList(int[] data){
for (int i = 0; i public boolean empty(){ if (top == null) return true; return false; } public int first(){ return top.getData(); } public void removeFirst(){ if (top != null) top = top.getLink(); } public IntLinkList clone(){ IntLinkList a = new IntLinkList(); if (top != null){ IntNode p = top; while (p != null){ a.add(p.getData()); p = p.getLink(); } } return a; } private static boolean equals(IntNode top1, IntNode top2){ //Your code here return false; //Dummy statement for testing - remove it. } //=========== Supplied code ============================= public IntLinkList() { //A constructor that creates an empty list. top = null; } public void add(int newItem) { //Add the newItem at the FRONT of the list. top = new IntNode(newItem,top); }//add public String toString() { String answer = ">"; } public void ordInsert(int newItem) { //Add the newItem so that the list remains sorted into //ascending order. This will not work unless the list //is currently in ascending order. IntNode prev = null; IntNode next = top; while(next!=null && next.getData() --------------------------- IntNode : /** * One particular node in a linked list of nodes containing int data. */ public class IntNode { private int data; //The data in this Node private IntNode link; //The link to the next Node public IntNode(int initData, IntNode initLink){ data = initData; link = initLink; } public int getData() {return data;} public IntNode getLink() {return link;} public void setData(int o) {data = o;} public void setLink(IntNode n) {link = n;} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started