my project is sort score of Student
using Linked List and sort algorithm
can i coding loop for input from user
and save value to node in linked list
and export or sort value like this ?
Thanks for help or discuss or give any idea
(any code is idea from this blog)
warning before post prob from this web (Curly braces { } may only be used when posting code.)
package javaapplication19;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static javaapplication19.LinkedList.addNode;
import static javaapplication19.LinkedList.printLinkedList;
public class JavaApplication19
public static void main(String [] args) throws IOException {
BufferedReader input = new BufferedReader(
new InputStreamReader(System.in));
Node head = null;
String name;
double score;
int counter=1;
System.out.print("Insert number of student : ");
int nStudent = Integer.valueOf(input.readLine());
for(int i=0;i<nStudent;i++) {
System.out.println("Number "+counter+".");
System.out.print("Student Score : ");
score = Double.parseDouble(input.readLine());
head = addNode(head,score);
counter++;
}
printLinkedList(head);
}
////////////////////////////////////////////////////////////////
package javaapplication19;
public class LinkedList
public static Node addNode(Node head,double point) {
Node newNode = new Node();
newNode.point = point;
newNode.next = null;
Node trav1, trav2;
trav1 = trav2 = head;
while(trav1 != null) {
trav2 = trav1;
trav1 = trav1.next;
}
if(trav1 != trav2) trav2.next = newNode;
else head = newNode;
return head;
}
public static void printLinkedList(Node head) {
Node trav = head;
int count=1;
while(trav != null) {
System.out.println("=============================");
System.out.println("No."+count+"");
System.out.println("Score : "+trav.point);
System.out.println("=============================");
count++;
trav = trav.next;
}
}
private LinkedList() {
}
//////////////////////////////////////////////////////////////
package javaapplication19;
import static java.util.Collections.sort;
public class Node
public double point;
public Node next;
public Node() {
this.point = 0.0;
this.next = null;
}
public Node(double point, Node next) {
this.point = point;
this.next = next;
}