Thread: Data structure View Single Post
 04-10-2013, 08:55 PM PM User | #1 raiqemlive New to the CF scene   Join Date: Apr 2013 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts Data structure Hello guys, nice to meet you all. I was looking forward to a solution to fix the problem that makes my algorithm die. It is about a linked-list, the elements are type Node which contains a integer, which represents the priority of the node. I wanted to sort the given input based on the int inside the node by sort-selection. Code: ```package partial1; import java.util.StringTokenizer; class Node { int v; public Node next; public Node(int val) { this.v = val; } public String show() { return " " + this.v; } public int valoare() { return v; } } public class Partial1 { public Partial1(String secv) { StringTokenizer st = new StringTokenizer(secv); Node t = new Node(Integer.parseInt(st.nextToken())); //head Node k = t; while (st.hasMoreTokens()) { int v = Integer.parseInt(st.nextToken()); k.next = new Node(v); k = k.next; } k.next = null; k = t; Node j = k.next; Node temp; while (k.next != null) { while (j.next != null) { if (k.valoare() < j.valoare()) { temp = k.next; k.next = j.next; j.next = temp; } j = j.next; } k = k.next; } k = t; while (k != null) { System.out.print("node= " + k.show() + "\n"); k = k.next; } } public static void main(String[] args) { Partial1 k = new Partial1("3 6 9 4 12 15"); } }``` The result is: 3 4 9 12 6 15