I am trying to "convert" this code to a method that will create node items. I know that I have to use a for loop but I cant figure out a way to get this done.
Original Code:
public class GenericLinkedListDemo
{
public static void main(String[] args)
{
LinkedList3<Entry> list = new LinkedList3<Entry>( );
Entry entry1 = new Entry(1);
list.addToStart(entry1);
Entry entry2 = new Entry(2);
list.addToStart(entry2);
Entry entry3 = new Entry(3);
list.addToStart(entry3);
}
What I did until now was create a method in the GenericLinkedListDemo that sends the parameter:
public class GenericLinkedListDemo
{
public static void main(String[] args)
{
LinkedList3<Entry> list = new LinkedList3<Entry>( );
addToList(list, 7);
to my method:
public static void addToList(LinkMaster<Entry> L, int n){
for (int i = n; i>0; i--) {
//This is where I want to put my "converted code"
}
}
I already did all the methods to create the node(LinkMaster). I just want to know how to make this piece of code above works in the way that I just need to send a parameter to the code.
addToListsupposed to do? What are you expecting to be added to the list by this method?