Saturday, February 28, 2009

Australian Voting

Australian Voting was fun, I set up 3 classes: Ballot, Candidate, and Election to simulate the election.

Ballot keeps track of a single ballot and which vote on that ballot is active. Candidate keeps a linked list of the Ballots that that Candidate owns, and it's responsible for redistributing those ballots when it loses. It also keeps track of how many votes it has so we can determine who has won. Election keeps an array of all the ballots and candidates, and runs the actual election process. The main() function reads in the input and drives the Election.

I built the 'array of intermingled linked lists' that Downing discussed when he introduced the project. It's a very elegant method of dealing with the ballots and minimizing the number of ballots which need to be recalculated.

To get the Candidate to be able to talk back to the Election to give its ballots back to other Candidates, I had to move all the class definitions above the method definitions. This isn't that hard, but it means you have to state all the methods as Election::AddBallot() instead of just AddBallot().

I used getline() and istringstream to parse the input, it worked better than using >> on cin for looking at each line.

Unfortunately, UVa was down all Sunday, so I couldn't test my project. All the inputs I gave it seemed to give good results, and it worked against the tests I found on Blackboard, but about 1 in the morning UVa messaged me with a Failure. It would have been nice to know that before the turn in deadline.....

Stable Marriage looks interesting, I remember this problem from my Algorithms class with Plaxton. Everybody always cracks up at the word 'man-optimal'. I'm glad we don't have to prove things about SMP, but it's going to be interesting to implement it efficiently.

2 comments:

  1. Please go to our website to view upcoming meeting info and to see the ETAC meeting agenda when it is obtainable. Due to COVID-19, conferences are currently being held nearly via Zoom and in-person at the City Hall... We’d be honored sogirlav.com to have you feature our free inventory photos on a billboard, flyer, menu or catalog. Indiana has the nation’s highest price of students who have contemplated suicide. The statistics are alarming, and addressing this well being disaster requires all of us. We've teamed up with WTHR to create the sources dad and mom and teachers need to speak about suicide prevention.

    ReplyDelete
  2. The 14x rollover requirements make this the easiest bonus to work off. There’s a really legit table video games menu right here, nicely as|in addition to} one of the best sportsbooks on-line. New gamers get one hundred pc as much as} $1000 within the on line casino, with a separate sportsbook bonus for the same amount. Almost 토토사이트 every on-line on line casino has some kind of supported cell platform, both as an app or mobile-friendly web site. However, not all of them provide the greatest person experience to match the desktop model - that’s why we only select on-line casinos that work flawlessly on the go.

    ReplyDelete