Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linked List Chapter 3 1. 2 Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.

Similar presentations


Presentation on theme: "Linked List Chapter 3 1. 2 Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the."— Presentation transcript:

1 Linked List Chapter 3 1

2 2

3 Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the possible values? – What operations will be needed? IMPLEMENTATION – How can this be done in C++? – How can data types be used? 3

4 Data structures A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Data structures are declared in C++ using the following: 4 syntax: struct structure_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3;. } object_names; struct product { int weight; float price; } apple, banana, melon;

5 5 http://www.cplusplus.com/doc/tutorial/structures/

6 6

7 Templates - Class templates A template parameter is a special kind of parameter that can be used to pass a type as argument: 7 http://www.cplusplus.com/doc/tutorial/

8 8

9 Linked List a linked list is a list in which the order of the components is determined by an explicit link member in each node the nodes are structs--each node contains a component member and also a link member that gives the location of the next node in the list an external pointer (or head pointer) points to the first node in the list 9

10 Nodes can be located anywhere in memory the link member holds the memory address of the next node in the list 10

11 Traversing a Linked List (single) 11

12 12

13 13

14 14

15 15

16 16

17 17

18 18

19 19

20 20

21 21

22 Figure 3.1 (text book) 22

23 23

24 Algorithm from e to h 24

25 Insertion - Algorithm (beginning) 25

26 26 Inserting a new node at the beginning of a singly linked list

27 Insertion - Algorithm (end) 27

28 28 Inserting a new node at the end of a singly linked list

29 Deleting a node at the beginning of a singly linked list 29

30 Deleting a node at the end of a singly linked list 30

31 Deleting a node from a singly linked list 31

32 32

33 Doubly Linked Lists An extension of a Singly Linked List Each node has two pointer – One pointing to the successor – One pointing to the predecessor They are used because they ease certain operations like the delete Element They are interesting for traversal as you can move in either directions 33

34 Doubly Linked Lists (Cont.) Most of our structures and algorithms will be implemented with the help of Doubly Linked Lists Although some operations are made easier to understand they also become a bit slower due to the overhead of extra pointers In addition to the head a pointer called tail is also maintained 34

35 Inserting in the Front 35

36 Inserting in the Front (cont.) 36

37 Inserting in the Front (cont.) 37

38 Inserting in the Front (cont.) 38

39 Inserting in the Front (cont.) 39

40 Deleting element 40

41 Circular Lists Nodes form a ring Each node has a successor 41

42 Inserting a Node at the Tail of a List Circular Lists 42

43 Inserting a Node at the Tail of a List Circular Lists (cont.) 43

44 Inserting a Node at the Tail of a List Circular Lists (cont.) 44

45 Inserting a Node at the Tail of a List Circular Lists (cont.) 45

46 Skip Lists Linked lists require sequential scanning for a search operation Skip lists allow for skipping certain nodes A skip list is an ordered linked list A Skip List with Evenly spaced nodes of different levels 46

47 Figure 3.17 (self study) Note: (no need) 3.5 to 3.8 47


Download ppt "Linked List Chapter 3 1. 2 Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the."

Similar presentations


Ads by Google