Monday, February 13, 2012

Australian Voting

If a professor tells you that declaring variables on the heap is not necessary for a project, simply do not do it. This is the lesson I am currently learning in regards to project 2, Australian Voting. The problem itself is very interesting, demonstrating a voting scheme I have never seen before. Put simply, all voters rank the candidates from their favorite to least favorite, and no candidate receives a majority vote in a round of voting, the losing votes are moved to their next ranked candidate. Seems simple enough, right? It is, except a doable problem can easily become a huge chore when terms like "new", "delete", and "pointer to a pointer" start being thrown around. While this is taking me and my partner a little longer than it should, I know that in the long run it will pay off, because we are learning things that will help not only later in this class, but later on in the industry as well.
  To be specific, we first started off using a linked list to store ballots (we will not go into details until after the project is due), and after that turned into a nightmare, we used vectors and arrays, and lastly we are using just arrays. The linked list poised the most problems, where we were deleting elements in the list twice unknowingly. The same thing happened with vectors, and it was not until later that the bad memory management was just the beginning of our problems. Lesson learned: Do not blow a project out of scope. Do not make it more than it has to be. If there are no requirements restricting use of the heap, by all means use the stack, and think about all the hassle you are saving yourself.

No comments:

Post a Comment