Cheap Essay logo
  • Home
  • Custom Papers
  • Dissertation Help
  • Essay Writing
  • My account
  • Order now
Order Now
Homework Help

A linked list of objects solution

2 min read
Posted on 
June 11th, 2022
Home Homework Help A linked list of objects solution

A Linked List of Objects

The file IntList.java contains an example of a linked list of integers A list of objects is a lot like a list of integers or a particular type of object such as a Magazine, except the value stored is an Object, not an int or Magazine.

// ***************************************************************

// FILE: IntList.java

//

// Purpose: Defines a class that represents a list of integers

//

// ***************************************************************

public class IntList

{

privateIntNode front; //first node in list

//—————————————–

// Constructor. Initially list is empty.

//—————————————–

publicIntList()

{

front = null;

}

//—————————————–

// Adds given integer to front of list.

//—————————————–

public void addToFront(intval)

{

front = new IntNode(val,front);

}

//—————————————–

// Adds given integer to end of list.

//—————————————–

public void addToEnd(intval)

{

IntNodenewnode = new IntNode(val,null);

//if list is empty, this will be the only node in it

if (front == null)

front = newnode;

else

{

//make temp point to last thing in list

IntNode temp = front;

while (temp.next != null)

temp = temp.next;

//link new node into list

temp.next = newnode;

}

}

//—————————————–

// Removes the first node from the list.

// If the list is empty, does nothing.

//—————————————–

public void removeFirst()

{

if (front != null)

front = front.next;

}

//————————————————

// Prints the list elements from first to last.

//————————————————

public void print()

{

System.out.println(“——————–“);

System.out.print(“List elements: “);

IntNode temp = front;

while (temp != null)

{

System.out.print(temp.val + ” “);

temp = temp.next;

}

System.out.println(“n———————–n”);

}

 

//*************************************************************

// An inner class that represents a node in the integer list.

// The public variables are accessed by the IntList class.

//*************************************************************

private class IntNode

{

publicintval; //value stored in node

publicIntNode next; //link to next node in list

//——————————————————————

// Constructor; sets up the node given a value and IntNode reference

//——————————————————————

publicIntNode(intval, IntNode next)

{

this.val = val;

this.next = next;

}

}

}

 

Write a class ObjList that contains arbitrary objects and that has the following methods:

Order an Essay Now & Get These Features For Free:

Turnitin Report

Formatting

Title Page

Citation

Outline

Place an Order
Share
Tweet
Share
Tweet
Calculate the price
Pages (275 words)
$0.00
Cheap Essay
Company
  • About Us
  • Coursework Writing
  • Custom Papers
  • Dissertation Help
  • Dissertation Writing
  • Essay Writing
Legal
  • Term Papers
  • Terms
  • Thesis Format
  • Thesis Statement
  • Why Choose Us
  • Write My Essay
How Our Service is Used:
Cheap Essay essays are NOT intended to be forwarded as finalized work as it is only strictly meant to be used for research and study purposes. Cheap Essay does not endorse or condone any type of plagiarism.
Subscribe
No Spam
© 2023 Cheap Essay. All rights reserved.
Cheap Essay will be listed as ‘Cheap Essay’ on your bank statement.