Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-------------------- IntLinkList : public class IntLinkList { private IntNode top; //The reference to the first Node //=========== Solution code ============================= public IntLinkList(int[] data){ for (int

image text in transcribed

--------------------

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;} }

QUESTION 2: RecuRSIVE LINKeD LIst oPERATIONs Add the following methods to the Int Link List class. These methods must be recursive. The IntlinkList class should have an equals method. The following function is already supplied in the IntLinkList class:+ public boolean equals(IntLinkList other)return equals (top,other.top);) Complete the recursive method private static boolean equals (IntNode topl, IntNode top2) which will return true if the two linked lists start that with the top pointers top1 and top2 are identical. They must be the same length, and all of the integers in the first list must exactly match all of the integers in the second list, in the same order). This method may not use any loops of any kind, directly or indirectly. The IntLinkList class already contains the ordInsert method discussed in class. Write a recursive method public void InSort) which will make use of the ordInsert method to sort the IntLinkList into ascending order. (Since ordInsert creates new nodes, the sorted list will consist of a completely new set of nodes. That's OK.) This method may not use any loops of any kind (except for the one in ordInsert)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

1. Diagnose and solve a transfer of training problem.

Answered: 1 week ago