Docsity

Linked Data Structures - Introduduction to Jave Programming - Lecture Slides, Slides of Java Programming

Partial preview of the text

Download Linked Data Structures - Introduduction to Jave Programming - Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Linked Data Structures

Announcements

  • Homework due on Monday!

What is a linked list?

A linked list simply a list where each element is linked to the next one A real world example of this is a train: each car links to the car in front and behind

Previous linked lists

We have actually already seen some linked list structures in this class:

  • Family tree
  • Files/Folders on a computer

Wrapping listed items

Often times linked lists are annoying to use directly, so we provide a wrapper class to:

  • Keep track of a position
  • Easily add to the end of the list
  • Enable removing of elements
  • Searching the list or providing any other useful functionality An object that can step through the list is called an iterator (See: BasicLinkedList.java)

Doubly linked list

Nodes could remember both the previous node and the next node (called doubly linked list) This makes it easier to add/remove elements and also allows you go to backwards through the list (See: Train.java)

Stack

A stack is much like putting junk in a bag:

  • The first thing you put in the bag is the last item out Stacks normally have 2 methods: Push(Node) - puts an item on the top Pop() - takes off the top item and returns it (Computers store your program as a stack) (See: Stack.java)

Data structures: Array

Data structures: Linked list

Data structures: Stack

Hash table

A hash table is a very efficient way of storing Which is easier to find your HW in?

  1. A single large stack (unsorted)?
  2. 26 stacks based on your last name (each individual stack is not sorted) 1. 2.

Hash table

Hash tables try to make many piles of equal size to aid in searching To do this, a hash table puts every element in a psuedo-random pile To find a paper in a pile, we then simply go to the pile where it should be and find it (See: HashTable.java)

Arrays vs. Linked lists