week4.pptx - Lists ADT(brief intro Abstract Data Type A...

This preview shows page 1 - 6 out of 23 pages.

Image of page 1

Subscribe to view the full document.

Lists
Image of page 2
ADT (brief intro): Abstract Data Type A DESCRIPTION of a data type The data type can be anything: lists, sets, trees, stacks, etc. What we want to do at the ADT level is describe what it is and what it should do We don’t worry about HOW it does it There’s no definite rule for what operations must be supported for each type Use what makes sense.
Image of page 3

Subscribe to view the full document.

Lists: Things we know about lists: The items have an order One comes after another - this doesn’t mean they’re “ordered” in any purposeful way, but there’s a built in order to the elements in a list The list has a size (n elements in the list) Data in a list can be duplicated All elements in the list are of the same data type
Image of page 4
List operations we might want: push(x)- add to end of list insert(x,k) adds item x to list at kth position remove (Node *node) – removes a node from the list removekth(int kth) – removes the node at the kth position from the list pop() – removes the last element from the list size() - gives you number of elements in list isEmpty() – returns true iff the list is empty find(x) – return the position of x in the list (usually -1 if not in list) findkth(k) – return the item at the kth position in the list printList() – you figure it out … I’m sure there are other things you’d want to be able to do with a list.
Image of page 5

Subscribe to view the full document.

Linked List (versus Array): Every element in a linked list consists of at a minimum 2 parts: The data A pointer to (aka the address of ) the element coming next in the list No fixed size (no limit on the number of elements in the list) No “wasted space” No empty spaces in between elements in the list Sequential access (as opposed to random access, like an array) 3 7 4 2 NULL Nodes in a linked list
Image of page 6
You've reached the end of this preview.
  • Spring '08
  • HARVEY

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern