1 Replies - 221 Views - Last Post: 02 December 2013 - 03:25 AM Rate Topic: -----

#1 cartertevin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 10-July 11

How do I apply insertion sort to a <List> of objects?

Posted 02 December 2013 - 03:09 AM

I have a <List> of objects that have a certain number associated with each. I call a method in the Object to supply me with that special number. How can I apply insertion sort, sorting it from least to greatest, using the number output of the objects in the <List>?
Is This A Good Question/Topic? 0
  • +

Replies To: How do I apply insertion sort to a <List> of objects?

#2 cartertevin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 10-July 11

Re: How do I apply insertion sort to a <List> of objects?

Posted 02 December 2013 - 03:25 AM

View Postcartertevin, on 02 December 2013 - 03:09 AM, said:

I have a <List> of objects that have a certain number associated with each. I call a method in the Object to supply me with that special number. How can I apply insertion sort, sorting it from least to greatest, using the number output of the objects in the <List>?

This is the basic idea in an implementation I got so far:
 	for (int e = 1; e < testHand.size(); ++e){
    		
    		int ins = e;
    		while(ins>0 && testHand.get(ins-1).getNumber() > testHand.get(ins).getNumber()){
    			Card iSwap; 
    			iSwap = testHand.get(ins);
    			testHand.get(ins).equals(testHand.get(ins - 1));
    			testHand.get(ins - 1).equals(iSwap);
    			--ins;
    			//this.teachersList[this.teachersSize].getTeacherNum() = this.teachersSize -1;
    		}
    		
    	}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1