Can you help me choose the correct data structure? | Sololearn: Learn to code for FREE!


Can you help me choose the correct data structure?

Hello everyone. I am working on a programming exercise. I should output symbol of the player that would win a tic tac toe game (on paper with unlimited space). I get input in this format: X 5 2 O 5 3 X 7 4 O 6 3 ... The numbers are x and y coordinades of the ticked cell. My problem is, I don't know which data structure should I use to save loaded moves. Currently I use custom class for all checked cells. The class stores symbol of the player (O or X), x and y coordiates of the cell and reference to all 8 cells touching it (if checked). I store all the cell objects in a list, but I feel there is a better solution. I need to check if there are 5 symbols of the same player in any direction after each move. The game can have up to 500.000 rounds and the cootrdinates have values 0 to 1.000.000 in both x and y directions.

10/24/2018 8:43:23 PM

Jan Štěch

1 Answer

New Answer


Maybe matrixes/lists? Just remember that nothing is unlimited, you may add a limit anywhere.