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

Page 1 of 1

## 1 Replies - 155 Views - Last Post: 02 December 2013 - 03:25 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=335439&amp;s=f43e8cbc3ec3f9d955d759a8105f2250&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 cartertevin

• New D.I.C Head

Reputation: 0
• 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

• New D.I.C Head

Reputation: 0
• 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

cartertevin, 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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }