thats using I h8 to say it Linked Lists
JAVA
Started by
o0MattE0o
, Jun 03 2005 10:08 AM
#31
Posted 10 June 2005 - 08:22 AM
thats using I h8 to say it Linked Lists
#32
Posted 10 June 2005 - 08:57 AM
can some one help me turn this
into a linked list version
in my listNode
LinkedList
package sets_and_data_structures; private void sortByResult() { int listLength = numOfComp; for (int pass = 0; pass < listLength - 1; pass++) { for (int i = 0; i < listLength - pass - 1; i++) { if (list[i + 1].hasResult() && (!list[i].hasResult() || (list[i + 1].hasResult() && list[i].getResult() > list[i + 1].getResult()) )) { Competitor t = list[i]; list[i] = list[i + 1]; list[i + 1] = t; } } } } //sortByResult
into a linked list version
in my listNode
ListNode(Competitor competitor, ListNode node) { data = competitor; nextNode = node; } ListNode getNext() { return nextNode; }
LinkedList
public void addCompetitor(Competitor insertItem){ if ( isEmpty() ){ // firstNode and lastNode refer to same competitor firstNode = lastNode = new ListNode(insertItem); numOfComp++; } else { // firstNode refers to new node firstNode = new ListNode(insertItem, firstNode); numOfComp++; } }
Edited by o0MattE0o, 10 June 2005 - 10:45 AM.
#33
Posted 10 June 2005 - 01:03 PM
This might help a little more but I need to do this again and again till the number go 23, 20, 15, 10
but I be using Object in my final version instead of int
but I be using Object in my final version instead of int
#34
Posted 10 June 2005 - 03:12 PM
I just worked out how to do what the picture dose but how would I get the do the others?
public void startListingByResult() { ListNode firstResult = firstNode; ListNode secoundResult = firstNode.getNext(); if (firstResult.getCompetitor().getResult() > secoundResult.getCompetitor().getResult()) { firstResult.nextNode = secoundResult.nextNode; secoundResult.nextNode = firstResult; firstNode = secoundResult; System.out.println("Linked List Sorted"); print(); } else { System.out.println("Linked List Already Sorted"); print(); } }
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users