Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

JAVA


  • Please log in to reply

#31
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
thanx for you help but I added it in know but I might need help with anouther one...

thats using I h8 to say it Linked Lists :tazz:
  • 0

Advertisements


#32
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
can some one help me turn this
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.

  • 0

#33
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
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

Posted Image
  • 0

#34
o0MattE0o

o0MattE0o

    Member

  • Topic Starter
  • Member
  • PipPip
  • 29 posts
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();
    }
  }

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP