Question
How do I make this progam in java into a linked list? // the Node class class Node { private int data; private Node link;
How do I make this progam in java into a linked list?
// the Node class
class Node
{
private int data;
private Node link;
// constructor
public Node()
{
this.data = 0;
this.link = null;
}
// accessor and mutator for the data component
public int getData()
{
return this.data;
}
public void setData(int data)
{
this.data = data;
}
// accessor and mutator for the link component
public Node getLink()
{
return this.link;
}
public void setLink(Node link)
{
this.link = link;
}
}
// the List class
public class List
{
public static final int MAX_SIZE = 50;
private Node head;
private Node tail;
private Node curr;
private int num_items;
// constructor
// remember that an empty list has a "size" of -1 and its "position" is at -1
public List()
{
num_items= -1;
head = new Node();
curr=head;
}
// copy constructor
// clones the list l and sets the last element as the current
public List(List l)
{
}
// navigates to the beginning of the list
public void First()
{
}
// navigates to the end of the list
// the end of the list is at the last valid item in the list
public void Last()
{
}
// navigates to the specified element (0-index)
// this should not be possible for an empty list
// this should not be possible for invalid positions
public void SetPos(int pos)
{
}
// navigates to the previous element
// this should not be possible for an empty list
// there should be no wrap-around
public void Prev()
{
}
// navigates to the next element
// this should not be possible for an empty list
// there should be no wrap-around
public void Next()
{
}
// returns the location of the current element (or -1)
public int GetPos()
{
}
// returns the value of the current element (or -1)
public int GetValue()
{
}
// returns the size of the list
// size does not imply capacity
public int GetSize()
{
}
// inserts an item before the current element
// the new element becomes the current
// this should not be possible for a full list
public void InsertBefore(int data)
{
}
// inserts an item after the current element
// the new element becomes the current
// this should not be possible for a full list
public void InsertAfter(int data)
{
}
// removes the current element (collapsing the list)
// this should not be possible for an empty list
public void Remove()
{
}
// replaces the value of the current element with the specified value
// this should not be possible for an empty list
public void Replace(int data)
{
}
// returns if the list is empty
public boolean IsEmpty()
{
}
// returns if the list is full
public boolean IsFull()
{
}
// returns if two lists are equal (by value)
public boolean Equals(List l)
{
}
// returns the concatenation of two lists
// l should not be modified
// l should be concatenated to the end of *this
// the returned list should not exceed MAX_SIZE elements
// the last element of the new list is the current
public List Add(List l)
{
}
// returns a string representation of the entire list (e.g., 1 2 3 4 5)
// the string "NULL" should be returned for an empty list
public String toString()
{
}
}
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