EECS

# Lec15LinkedStructures_2per.pdf - The University Of Michigan...

• 9

This preview shows pages 1–3. Sign up to view the full content.

1 The University Of Michigan Andrew M. Morgan EECS402 Lecture 15 Savitch Ch. 17 Linked Data Structures EECS 402 EECS 402 Andrew M Morgan 2 Sorted Arrays As Lists Arrays are used to store a list of values Arrays are contained in contiguous memory Recall inserting a new element in the middle of an array requires later elements to be "shifted". For large lists of values, this is inefficient. void insertSorted(int value, int &length, int list[]) { int i = length - 1; while (list[i] > value) { list[i + 1] = list[i]; i--; } list[i + 1] = value; length++; } Shifting array elements that come after the element being inserted 4 8 13 29 37 4 6 8 13 29 37 Insert 6

This preview has intentionally blurred sections. Sign up to view the full version.

2 EECS 402 EECS 402 Andrew M Morgan 3 Sorted Arrays, Cot'd Due to the need to "shift" elements, sorted arrays are: Inefficient when inserting into the middle or front Inefficient when deleting from the middle or front Efficient for searching Since inserting and deleting are common operations, we need to find a data structure which allows more efficiency Contiguous memory will not work will always require a shift "Random" placement requires "random" memory locations Dynamic allocation provides "random" locations, and means that the list can grow as much as necessary The maximum size need not be known ever This is not true for arrays, even dynamically allocated arrays EECS 402 EECS 402 Andrew M Morgan 4 Intro To Linked Lists A linked list is a data structure which allows efficient insertion and deletion. Consists of "nodes". Each node contains: A value - the data being stored in the list A pointer to another (the next) node By carefully keeping pointers accurate, you can start at the first node, and follow pointers through entire list.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern