Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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