Last active
August 29, 2015 13:57
-
-
Save talllguy/9731488 to your computer and use it in GitHub Desktop.
Playing with LinkedLists
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
public class MyLinkedList { | |
private static node head; | |
public void DisplayList(node q) | |
{if (q != null) { | |
System.out.println(q.data); | |
DisplayList(q.next);}} | |
public void Buildlist() throws IOException | |
{node q = new node(0,null); | |
node head = q; | |
String oneLine; | |
BufferedReader indata = new BufferedReader(new InputStreamReader(System.in)); // read data from terminals | |
System.out.println("How many nodes?\n"); | |
oneLine = indata.readLine(); // always need the following two lines to read data | |
head.data = Integer.parseInt(oneLine); | |
for (int i=1; i<=head.data; i++) | |
{System.out.println("A new value please\n"); | |
oneLine = indata.readLine(); | |
int num = Integer.parseInt(oneLine); | |
node p = new node(num,null); | |
q.next = p; | |
q = p;}} | |
public static void main(String[] args) throws IOException | |
{MyLinkedList mylist = new MyLinkedList(); | |
mylist.Buildlist(); | |
mylist.DisplayList(head);} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment