by yolo69420 · 4y ago · 0 comments
- read file
- start at beginning; if you encounter separator, add new entry to an array. if you encounter newline, save entire current array as a new line to an array of lines.
- do lexicographical sort of arrays (can just use qsort for this).
- if the test q actually wants you to parse out numbers and shit like that, nothing about the structure changes, you just have to record some extra info when parsing values and then use a different comparison depending on the type in the function you pass to qsort
I dare say someone programming algorithms in a kernel or writing code for custom file systems should be able to do this. OK 15 min may be tight if you're nervous but you should get there.
Things get even weirder when you throw non-Latin characters in the mix. May such parsers predate widespread use of UTF-8.
Personally I’d do it by storing indexes into the CSV contents instead of using null terminated C strings.
Doing all of this in just 15 minutes is going to be hard.
By the way, your solution as described is wrong, since it sorts each row independently. What you’d need to do is store all the data in a transposed format i.e an array of pointers to column arrays, then sort the array by giving qsort a comparison function that looks at the first entry in each column.