Join Simon Allardice for an in-depth discussion in this video Sorting arrays of custom objects, part of Foundations of Programming: Data Structures.
- View Offline
…In object orientated languages, you often have arrays of your own…custom objects, not just arrays of simple numeric or even text values.…By default, there's usually no problem creating an…array of custom objects, but if you then…ask that array to sort those objects using…the built in sort functionality in the language.…It simply won't know how to do it.…Because you need to provide a little more information before…you can write the equivalent of myarray.sort and have that work.…Because if we have, for example, an array of employee…objects, with each one containing multiple properties, multiple pieces of data.…
Like employee ID, first name, last name, hire date, department.…But what does it mean to sort employee objects?…If we want to sort these, should we just…look inside each object and sort them by employee ID?…Well, that might work, but if you're using this data structure to build…an employee directory, you'd probably prefer to sort by the last name ascending.…And then, within that, you'd want to sort by the first name.…
Starting with simple ways of grouping data like arrays and structs, together you'll explore gradually more complex data structures, like dictionaries, sets, hash tables, queues and stacks, links and linked lists, and trees and graphs. Simon keeps the lessons grounded in the real world and answers the "why" behind many data-structuring decisions: Why use a hash table? Why is a set useful? Why avoid arrays? When you're finished with the course, you'll have a clear understanding of data structures and understand how to use them in whatever language you're programming in, today or 5 years from now.
- What is a data structure?
- Using C-style structs and arrays
- Sorting and searching arrays
- Working with singly and doubly linked lists
- Using stacks for last-in, first-out (LIFO) structures
- Using queues for first-in, first-out (FIFO) structures
- Working with hash tables
- Understanding binary search trees (BSTs)
- Learning about graphs