How should I organize my code? via /r/learnprogramming


How should I organize my code?

Currently, I have all the sorting algorithms I wrote (quicksort, heapsort, etc) in one class called SortingAlgorithms

Each sorting algorithm is in its own static method. In my main method, I initialize my unsorted array then have a bunch of method calls. I just comment out all the ones except the one I want to use. Overall, my program has exceeded 400 lines and it's getting a bit messy. I'm looking for a way to organize my code but still have it centralized so I can run anything I want from one space (so one main method for everything). I was thinking making a sorter class, putting all my algorithms in there, then in another file with my main creating a sorter object then calling the methods from there. Or putting each algorithm in its own file as its own class then making an object of the one I want. For example HeapSort heapSorter = new HeapSort(array);

does that even make sense?

Submitted July 15, 2017 at 10:49PM by eatingpoopinrobarts
via reddit http://ift.tt/2uriArC

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s