Extension of linked list - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Extension of linked list

Description:

Title: PowerPoint Presentation Author: PC User Last modified by: zhen-Air Created Date: 3/11/2001 5:06:34 PM Document presentation format: On-screen Show (4:3) – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 30
Provided by: PCU105
Learn more at: https://www.cs.wcupa.edu
Category:

less

Transcript and Presenter's Notes

Title: Extension of linked list


1
Extension of linked list
  • Zhen Jiang
  • West Chester University
  • zjiang_at_wcupa.edu

2
Outline
  • Double Cyclic Linked List
  • Queue Stack
  • Binary Tree
  • Expression Tree
  • Networks

3
(Single) Linked list
node
NULL
4
Double Cyclic Linked List
node
NULL
5
Queue
node
Delete an item from the tail
NULL
Insert a new item at the head
6
Stack
node
NULL
Insert a new item at the head
Delete an item from the head
7
  • Implementation of stack with template
  • http//www.cs.wcupa.edu/zjiang/csc513_template.pp
    t

8
  • Use of Stack
  • Project 5
  • Reading information via file
  • http//www.cs.wcupa.edu/zjiang/530_proj5_file.pdf
  • Three stacks, one for each , (), and .
  • Left gt push/insert
  • Right gt pop/delete the closest left symbol
  • Evaluation of (postfix) expression

9
  • (5 4) 3
  • 5 (4 3)
  • 5 4 3
  • 5 (4 3)
  • 5 4 3
  • 5 4 3
  • 5 4 3
  • 5 4 3

10
  • Read the formula from left to right
  • Number gt push
  • Binary operator gt 2 pops
  • Right number popped first
  • Then, left number popped.
  • Calculate result ltsecondgt op ltfirstgt
  • Push (result)
  • Until expression reading finishes and only one
    (final) result is left in stack

11
Disorder of the link connection
node
NULL
12
Tree
  • Definition
  • Each node u has n(u) children
  • Considering the parent-child relationship is
    undirected, there is no cycle in a tree
  • There is only one node called the root in the
    entire tree. It has children only but no parent.

13
Binary Tree
  • Definition
  • Definition of tree (3)
  • For each node u, n(u)lt3
  • LltSltR
  • lt is a relation between any two nodes in the tree

14
  • Constructor
  • Assume each node has a number value so that we
    have the relation lt
  • Given a sequence n1, n2, n3, , ni,
  • n1 -gt set root unit (node)
  • ni -gt call insertion(node, ni)

15
  • Insertion(p, n)
  • If (p-gtv lt n)
  • If p-gtR not empty
  • Insertion (p-gtR, n)
  • else
  • Set p-gtR
  • If (p-gtv gt n)
  • Similar to the case (p-gtv lt n)

16
  • Travel (print out all node values)
  • Infix travel, L-gtS-gtR
  • Postfix travel, L-gtR-gtS
  • Prefix travel, S-gtL-gtR

17
  • Infix travel
  • If node is not empty, Infix_print (node)
  • Infix_print (p)
  • If (p-gtL) infix_print(p-gtL)
  • Cout ltlt p-gtv
  • If(p-gtR) infix_print (p-gtR)

18
  • Search
  • If node is not empty, Search (node, n)
  • Search (p, n)
  • If (p-gtv n) return true
  • If (p-gtv lt n) return Search (p-gtR, n)
  • If (p-gtv gt n) return Search (p-gtL, n)
  • Terminating condition if (!p) return false

19
  • Deletion
  • Delete the root node
  • If node is empty
  • If node-gtL (or node-gtR) is empty
  • tmp node-gtR (or node-gtL)
  • Delete node
  • node tmp

20
  • If neither node-gtL nor node-gtR is empty
  • If node-gtL-gtR is empty
  • node -gt v node-gtL-gtv
  • tmp node-gtL-gtL
  • Delete node-gtL
  • node-gtL tmp
  • Else
  • tmp node-gtL
  • While (tmp-gtR-gtR) tmp tmp-gtR
  • node-gtv tmp-gtR-gtV
  • tmp2 tmp-gtR-gtL
  • Delete tmp-gtR
  • tmp-gtR tmp2

21
  • See if you can find a certain value in the tree
    and delete it!
  • Delete (n)
  • If (node-gtv n) delete node
  • If (node-gtv lt n)
  • deletion (node, node-R, n, 1)
  • If (node-gtv gt n)
  • deletion (node, node-L, n, 0)

22
  • Deletion (parent, start, value, flag)
  • If start is empty // not found, done!
  • If start-gtv lt value
  • If start-gtv gt value
  • Else //start-gtv value
  • If both start-gtL and start-gtR are empty
  • Delete start
  • If (flag)Parent -gtR NULL
  • Else Parent -gt L NULL
  • If start-gtL (or start-gtR) is empty

23
  • Deletion (parent, start, value, flag)
  • Else //start-gtv value
  • If start-gtL (or start-gtR) is empty
  • If (flag) Parent-R Start-gtR (or start-gtL)
  • Else Parent-gtL Start-gtR
  • Delete start
  • If neither start-gtL nor start-gtR is empty

24
  • If start-gtL-gtR is empty
  • start -gt v start-gtL-gtv
  • tmp start-gtL-gtL
  • Delete start-gtL
  • start-gtL tmp
  • Else
  • tmp start-gtL
  • While (tmp-gtR-gtR) tmp tmp-gtR
  • start-gtv tmp-gtR-gtV
  • tmp2 tmp-gtR-gtL
  • Delete tmp-gtR
  • tmp-gtR tmp2

25
Expression Tree
  • Definition
  • Definition of binary tree (5)
  • All leaves are numbers, and all intermediate
    nodes are operators
  • To simplify the discussion in this class, we use
    binary operators only.

26
  • Evaluation
  • If node is not empty, R_E(node)
  • R_E(p)
  • If p-gtv is not digit
  • Lvalue R_E(p-gtL)
  • Rvalue R_E(p-gtR)
  • Return Lvalue ltp-gtvgt Rvalue
  • Else
  • Return p-gtv

27
  • Print
  • Postfix
  • Construction
  • From infix format
  • http//www.cs.wcupa.edu/zjiang/csc530_expressionT
    ree.htm

28
Network
  • Graph table
  • http//www.cs.wcupa.edu/zjiang/csc530_graph_table
    .pdf
  • Depth first search
  • http//www.cs.wcupa.edu/zjiang/csc530_depth.pdf
  • Width first search
  • http//www.cs.wcupa.edu/zjiang/csc530_width.pdf
  • Shortest path construction
  • http//www.cs.wcupa.edu/zjiang/csc530_shortestpat
    h.pdf

29
  • Spanning (travel)
  • Project 7
Write a Comment
User Comments (0)
About PowerShow.com