gagirl1105 0 Newbie Poster

Hey, all I'm working on a homework assignment which includes the creation of an insertion sort method to go through an Array List of basketball games. The basketball games are formatted:

                public Game (String homeTeam, int htScore, String opponent, int oppScore)
                {
                    this.homeTeam = homeTeam;
                    this.htScore = htScore;
                    this.opponent = opponent;
                    this.oppScore = oppScore;
                }

and I'll need to sort alphabetically by home team name.

So far, I've come up with:

             public void sortGames ()
                {
                    System.out.println("Sorting...");


               for(int i = 1; i < theDB.size(); i++)
               { int position = i;
                 String str = this.getGame(i).getHomeTeam();
                 String prev = this.getGame(position).getHomeTeam();
                 //Game before =  this.getGame(position);


                  while( position > 0 && prev.compareTo(str) > 0)
                  {theDB.add(position, this.getGame(position));
                     position--;
                     prev = this.getGame(position).getHomeTeam();
                  }
               }







                    System.out.println("Finished sorting...");

                }

Which doesn't make any changes to the Array List (theDB).

I'm having trouble figuring out how to apply an insertion sort to an Array List.
Any help or suggestions would be appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.