.gitignore | ||
books.txt | ||
CMakeLists.txt | ||
library.cpp | ||
library.h | ||
main.cpp | ||
node.h | ||
README.md |
CSE 1384
Lab 9 - Sorting/Searching
-
When it comes to linked lists, linear search is almost always better than binary search. Why?
- Binary search works best when you have direct access to the data. With linked lists, you cannot access members of the list by an index. This means you have to iterate through the entire list. Linear search is the best option because you had to iterate through it anyways.
-
What sorting algorithm did you use?
- I used insertion sorting for the
Library::reverseSort()
function.
- I used insertion sorting for the
-
What was your strategy while building your shuffle? How does your shuffle work?
-
My
Library::shuffle()
function does the following:-
Seeds the random generator with the current time using ctime and cstdlib
-
Iterates through the list size, generating a new random integer and cutting it into a single digit
-
Swaps the title and author of each list member with another member at
i + n
, where i is the index of the current member and n is the randomly generated integer
This effectively shuffles the list with each member pseudo-randomly swapped with another member.
-
-
Sources
Reference : <cstdlib> : srand - cplusplus.com
cplusplus.com was used to reference the usage of srand and rand. I adopted the binary search and insertion sort examples from zyBooks to be compatible with the singly-linked list from library.h
.