-----------------------------------------------------------
import java.util.*;
public class LinkedList
{
private CarNode head = null;
public void addCar(String name , int hk , int year)
{
//If head = null then create the first node
if(head == null)
{
head = new CarNode(name,hk,year,null);
}
else
{
//If there are more than 1 node
head = new CarNode(name,hk,year,head);
}
}
public String viewAll()
{
StringBuffer str = new StringBuffer();
for(CarNode cursor = head ; cursor != null ; cursor = cursor.getNext())
{
//Appending car by car until there are no more cars
str.append(cursor+"\n");
}
return new String(str);
}
}
-----------------------------------------------------------
public class CarNode
{
private String namn;
private int hk;
private int year;
private CarNode next;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.