Created
April 29, 2016 05:12
-
-
Save sinanduman/5eeaa053a54b31cc4887c3b1f52834ad to your computer and use it in GitHub Desktop.
Simple Linked List add and list implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oasis; | |
public class Tree { | |
public Student head = null; | |
public void add(Integer number, String name, String surname) { | |
Student student = new Student(number, name, surname); | |
if (head == null) { | |
head = student; | |
} else { | |
Student temp = head; | |
while (temp.next != null) { | |
temp = temp.next; | |
} | |
temp.next = student; | |
} | |
} | |
@Override | |
public String toString() { | |
return "Tree [head=" + head + "]"; | |
} | |
public void list() { | |
Student temp = head; | |
while (temp != null) { | |
System.out.println(temp.toString()); | |
temp = temp.next; | |
} | |
} | |
} | |
class Student { | |
public Integer number; | |
public String name; | |
public String surname; | |
public Student next; | |
public Student() { | |
super(); | |
} | |
public Student(Integer number, String name, String surname) { | |
this.number = number; | |
this.name = name; | |
this.surname = surname; | |
} | |
@Override | |
public String toString() { | |
return "Student [number=" + number + ", name=" + name + ", surname=" + surname + ", next=" + next + "]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment