data structures and applications n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Data Structures and Applications PowerPoint Presentation
Download Presentation
Data Structures and Applications

Loading in 2 Seconds...

play fullscreen
1 / 18

Data Structures and Applications - PowerPoint PPT Presentation


  • 155 Views
  • Uploaded on

Data Structures and Applications. Hao Jiang Computer Science Department Boston College. Linked List. head. 1. 2. 3. 4. null. … Node head; Node v1 = new Node(1); Node v2 = new Node(2); Node v3 = new Node(3); Node v4 = new Node(4); head = v1; v1.next = v2; v2.next = v3;

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Data Structures and Applications' - aracely


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
data structures and applications

Data Structures and Applications

Hao Jiang

Computer Science Department

Boston College

linked list
Linked List

head

1

2

3

4

null

Node head;

Node v1 = new Node(1);

Node v2 = new Node(2);

Node v3 = new Node(3);

Node v4 = new Node(4);

head = v1;

v1.next = v2;

v2.next = v3;

v3.next = v4; v4.next = null;

class Node {

public int d;

public Node next;

public Node(int d)

{

this.d = d;

next = null;

}

}

some properties
Some Properties

head

1

2

3

4

null

A list is dynamic: the length of a list is determined in the runtime.

Some operations such as insertion and deletion are cheaper

than the data structure array.

insert
Insert

head

1

2

3

4

null

100

Insert a new node at position 1.

insert in the front
Insert in the Front

head

1

2

3

4

null

100

Insert a new node at position 0.

insert at the end
Insert at the End

head

1

2

3

4

100

null

Insert a new node at the end.

delete
Delete

head

1

2

3

4

null

Delete a new node at position 1.

delete from the front
Delete from the Front

head

1

2

3

4

null

Delete a node at position 0.

delete the last node
Delete the Last Node

head

1

2

3

4

null

null

Delete the last node in the list.

a list of objects
A List of Objects

head

obj1

obj2

obj3

obj4

null

class Node {

public Object d;

public Node next;

public Node(Object d)

{

this.d = d;

next = null;

}

}

a more accurate illustration
A More Accurate Illustration

obj1

obj2

obj3

obj4

head

null

A list of objects.

list class
List Class

public class List {

private Node head;

public List() { head = null; }

public boolean isEmpty() { return (head == null); }

public int length(Node h) {

if (h == null) return 0;

return 1 + length(h.next);

}

public int length() { return length(head); }

public void append() {…}

public void insert(int n, Object d) {…}

public Object delete(int n) {…}

public void print() {…}

}

queue
Queue
  • A queue is a first-in-first-out linear data structure.
  • It supports two operations:
    • void enQueue(Object d)
    • Object deQueue()

Data

Out

Data

In

stack
Stack
  • A stack is a first-in-last-out linear data structure.
  • It supports two operations:
    • void push(Object d)
    • Object pop()

top of the stack

bottom of the stack

queue based on list
Queue based on List

public class Queue {

private List list;

public Queue() {

list = new List();

}

public void enQueue(Object d) {

list.append(d);

}

public Object deQueue() {

Object t = list.getHead();

list.delete(0);

return t.d;

}

}

stack based on list
Stack based on List

public class Stack {

private List list;

public Stack() {

list = new List();

}

public void push(Object d) {

list.insert(0, d);

}

public Object pop() {

Node t = list.getHead();

list.delete(0);

return t.d;

}

}

simulation
Simulation
  • Application of the Queue

Gas Station

car1

car2

car3

car4

Top of the line

End of the line

How long does everyone have to wait?

How long can the line be?

language parser
Language Parser
  • We can use stacks to make language parsers.
  • ( ( 1 + 2 ) / 3 ) = ?

2

1

+

3

)

( (

1 + 2

3

3

/

1

The result is

1.

)

/ 3