Chapter 4: Lists 2004 년가을학기. 강경란 정보및컴퓨터공학부, 아주대학교
|
|
- Herbert Fisher
- 6 years ago
- Views:
Transcription
1 Chapter 4: Lists 2004 년가을학기 강경란 정보및컴퓨터공학부, 아주대학교
2 1. Pointers 2. Singly Linked Lists Chapter 4 Lists 3. Dynamically Linked Stacks and Queues 4. Polynomials 5. Additional List Operations 6. Equivalence Relations 7. Sparse Matrices 8. Doubly Linked Lists -2/60-
3 1. List Terminology A collection of items accessible one after another beginning at the head and ending at the tail 2. Linked list head 3. Doubly linked list tail bat mat cat pat head 4. Circular list tail bat mat cat pat head tail bat mat cat pat -3/60-
4 List Example 1 - Single Node Case typedef struct list_node *list_pointer; typedef struct list_node { char data[4]; list_pointer link; (= list_node *link;) ; #define IS_EMPTY(ptr) (!(ptr)) list_pointer list_head = NULL; list_head = (list_pointer) malloc(sizeof(list_node)); strcpy(list_head ->data, bat ); list_head ->link=null; list_head head->data list_head Address of the first node b a t \0 0 list_head head->link -4/60-
5 1. Create a list 2. Insert a node 3. Delete a node 4. Print the list Operations onto the Lists typedef struct list_node *list_pointer; typedef struct list_node { int data; list_pointer link; list_node; -5/60-
6 Create a List list_pointer create2(int data1, int data2) { /* create a list of two nodes */ list_pointer first, second; first = (list _p pointer) malloc(sizeof(list ( _ node)); second = (list_pointer) malloc(sizeof(list_node)); second->link = NULL; second->data = data2; first->data = data1; first->link = second; second 20 return first; first 10 list_head = create2(10, 20); list_head -6/60-
7 Insert a Node (1/2) #define IS_FULL(ptr) (!(ptr)) Head of the list Insertion position void insert(list_pointer *ptr, list_pointer node, int key) Key value of the new node { list_pointer temp; temp = (list_pointer) malloc(sizeof(list_node)); if (IS_FULL(temp)){ fprintf(stderr, "The memory is full\n"); exit(1); temp->data = key; if (*ptr) { temp->link = node->link; node->link = temp; else { temp->link = NULL; *ptr = temp; -7/60-
8 Insert a Node (2/2) 1. Insert a node which has 10 as data into a null list list_head = NULL; insert(&list_head, list_head, 10); list_head Insert a node which has 50 as data at the back of the first node insert(&list_head, list_head, 50); list_head /60-
9 deleted node Delete a Node (1/2) void delete(list_pointer *ptr, list_pointer trail, list_pointer node) { Head of the list Preceding node /* trail is the preceding node. ptr is the head of the list */ if (trail) trail->link = node->link; else *ptr = (*ptr)->link; free(node); To delete the head node What if the list is empty, i.e. *ptr is NULL? How should the function be changed if ptr is just list_pointer? -9/60-
10 Delete a Node (2/2) 1. Example 1 list lst_head To be deleted delete(&list_head, list_head, list_head->link); 2. Example 2 list_head To be deleted delete(&list_head, NULL, list_head); -10/60-
11 Erasing a List void erase(poly_pointer *ptr) { /* erase the polynomial pointed to by ptr */ poly_pointer temp; while (*ptr) { temp = *ptr; *ptr = (*ptr)->link; free(temp); list_head erase(&list_head); -11/60-
12 Dynamically Linked Stacks and Queues Stack top bat mat cat pat Queue front bat mat cat pat rear -12/60-
13 Stacks #define MAX_STACKS 10 /* maximum number of stacks */ typedef struct { int key; /* other fields */ element; typedef struct stack *stack_pointer; typedef struct stack { element item; stack_pointer link; ; stack_pointer top[max_stacks]; 1. Initialization top[i]=null, 0 i<max_stacks 2. Boundary conditions IS_EMPTY(top[i]): no item is available in i-th stack IS_FULL(temp) : no memory space is available -13/60-
14 Stacks Insert an Item (1/2) void add(stack_pointer *top, element item) { /* insert an item at the top of a stack */ stack_pointer temp = (stack_pointer) malloc(sizeof (stack)); if (IS_FULL(temp)) { fprintf(stderr,"the memory is full\n"); exit(1); temp->item = item; temp->link = *top; *top = temp; What if top is just stack_pointer? -14/60-
15 Stacks Insert an Item (2/2) top[0] element new_item; new_ item.key=20; add(&top[0], new_item); top[0] /60-
16 Stacks Delete an Item (1/2) element delete (stack_pointer *top) { /* delete an item from a stack */ stack_pointer temp = *top; element item; if (IS_EMPTY(temp)) { fprintf(stderr,"the stack is empty\n"); exit(1); item = temp->item; *top = temp->link; free(temp); return item; -16/60-
17 Stacks Delete an Item (2/2) top[0] item = delete(&top[0]); printf( %d\n, item.key); top[0] /60-
18 Queues #define MAX_QUEUE 10 /* Maximum Number of Queues */ typedef struct queue *queue_pointer; typedef struct queue { element item; queue_pointer e link; ; queue_pointer front[max_queues], rear[max_queues]; 1. Initial condition front[i]=null, 0 i < MAX_QUEUES 2. Boundary conditions IS_EMPTY(front[i]): no item is available in i-th queue IS_FULL(temp): no memory space is available -18/60-
19 Queues Insert an Item (1/2) void addq (queue_pointer *front, queue_pointer *rear, element item) { /* insert an item at the rear of a queue */ queue_pointer temp = (queue_pointer) malloc(sizeof (queue)); if (IS_FULL(temp)) { fprintf(stderr,"the memory is full\n"); exit(1); temp->item = item; temp->link = NULL; if (*front) (*rear)->link = temp; else *front = temp; Queue was empty *rear = temp; -19/60-
20 Queues Insert an Item (2/2) front[0] rear[0] element item; item.key=50; addq(&front[0], &rear[0], item); front[0] rear[0] /60-
21 Queues Delete an Item (1/2) element deleteq (queue_pointer *front) { /* Delete an item from a queue */ queue_pointer temp = *front; element item; if (IS_EMPTY(*front)) { fprintf(stderr,"the queue is empty\n"); exit(1); item = temp->item; *front = temp->link; free(temp); return item; -21/60-
22 Queues Delete an Item (2/2) front[0] rear[0] item=deleteq(&front[0]); printf( %d\n, item.key); front[0] rear[0] /60-
23 Polynomials - Representation typedef struct poly_node *poly_pointer; typedef struct poly_node { int coef; int expon; poly y_p pointer link; coef expon link ; poly_pointer a,b,d; A(x) = 3x x a B(x) = 8x 14-3x x 6 b /60-
24 Polynomials Addition (1/3) 1. if (a-> expon == b->expon) a b front rear -24/60-
25 Polynomials Addition (2/3) 2. if (a-> expon < b->expon) a b front rear -25/60-
26 Polynomials Addition (3/3) 3. if (a-> expon > b->expon) a b front rear -26/60-
27 A Function for Polynomial Addition (1/4) poly_pointer padd (poly_pointer a, poly_pointer b) { /* return a polynomial which is the sum of a and b */ poly_pointer pointer front, rear, temp; int sum; rear = (poly y_p pointer)malloc(sizeof(poly (p y_ node)); if (IF_FULL(rear)) { fprintf(stderr, "The memory is full\n"); exit(1); front = rear; -27/60-
28 A Function for Polynomial Addition (2/4) while(a && b) { switch (COMPARE(a->expon, b->expon)) { case -1: /* a->expon < b->expon */ attach(b->coef,b->expon,&rear); b = b->link; break; case 0: /* a->expon = b->expon */ sum = a->coef + b->coef; if (sum) attach(sum,a->expon,&rear); a = a->link; b->link; break; case: 1 /* a->expon > a->expon */ attach(a->coef,a->expon,&rear); a = a->link; -28/60-
29 A Function for Polynomial Addition (3/4) /* copy the rest of list a and list b */ for (; a; a = a->link) attach(a->coef,a->expon,&rear); for (; b; b = b->link) attach(b->coef,b->expon,&rear); rear->link = NULL; /* delete the useless initial node */ temp = front; front = front->link; free(temp); return front; -29/60-
30 Polynomial Attachment (4/4) void attach(float coefficient, int exponent, poly_pointer *ptr) { /* create a node and attach it to the node pointed to by ptr */ poly_pointer temp; temp = (poly_pointer)malloc(sizeof(poly_node)); if (IS _ FULL(temp)) { fprintf(stderr, "The memory is full\n"); exit(1); temp->coef = coefficient; temp->expon = exponent; (*ptr)->link = temp; *ptr = temp; -30/60-
31 Analysis of padd m A( x ) + a ( m e 1 = am 1x +... n B( x) + b f 1 = b 1 x +... n where a i, b i 0, e m-1 > > e 0 0, f n-1 > > f 0 0, 0 0 x x e f number of coefficient additions min{m, n number of terms m + n number of exponent comparisons m + n f(m,n) = O(m+n) -31/60-
32 1. Zero polynomial Polynomial : Circularly Linked List a x x a /60-
33 A(x) = 3x x Polynomial Addition Circular List a B(x) = 8x 14-3x x b -1 D(x) = 11x 14-3x x x d /60-
34 Polynomial Addition Circular List (1/2) poly_pointer cpadd (poly_pointer a, poly_pointer b) { poly y_p pointer starta, d, lastd; int sum, done = FALSE; starta = a; a = a->link; b = b->link; d = get_node(); d->expon = -1; lastd = d; -34/60-
35 Polynomial Addition Circular List (2/2) do { switch (COMPARE(a->expon, b->expon)) { case -1: /* a->expon < b->expon */ attach(b->coef,b->expon,&lastd); b = b->link; break; case 0: /* a->expon == b->expon */ if (starta == a) done = TRUE; else { sum = a->coef + b->coef; if (sum) attach(sum,a->expon,&lastd); a = a->link; b = b->link; break; case: 1 /* a->expon > a->expon */ while (!done); lastd->link =d; return d; attach(a->coef,a->expon,&lastd); a = a->link; -35/60-
36 Additional Operations on Lists (1/5) 1. Base data structure typedef struct list_node *list_pointer; Typedef struct list_node { int data; list_pointer link; ; list_pointer list_head, list_head2; list_head list_head /60-
37 Additional Operations on Lists (2/5) 2. Finding the length (circular list) int length (list_pointer ptr) { list_pointer temp; int count = 0; if (ptr) { temp = ptr; do { count++; temp = temp->link; while (temp!= ptr); return count; printf( %d, length(list_head)); head)); printf( %d, length(list_head2)); -37/60-
38 Additional Operations on Lists (3/5) 3. Inverting list_pointer invert(list_pointer lead) { list_pointer middle, trail; middle = NULL; while (lead) { trail = middle; middle = lead; lead = lead->link; middle->link = trail; return middle; list_pointer list_head3 = invert(list_head); -38/60-
39 Additional Operations on Lists (4/5) 4. Concatenating list_pointer concatenate (list_pointer ptr1, list_pointer ptr2) { list_pointer temp; if (IS_EMPTY(ptr1)) return ptr2; else { if (!IS_EMPTY(ptr2)) { for (temp = ptr1; temp->link; temp = temp-> link); temp->link = ptr2; return ptr1; -39/60-
40 Additional Operations on Lists (5/5) 5. Inserting at the front (circular list) void insert_ front (list_pointer *ptr, list_pointer node) { /* ptr points to the last node in the list */ if (IS_EMPTY(*ptr)) { *ptr = node; node->link = node; else { node->link = (*ptr)->link; (*ptr)->link = node; list_pointer i t node_p=malloc(sizeof(list_node)); d insert(&list_head, node_p); list_head is assumed to point to the last node of the list -40/60-
41 1. Equivalence relations 1) For any polygon x, x x Equivalence Relations 2) For any two polygons, x and y, if x y then y x 3) For any three polygons, x, y and z, if x y and y z, x z 2. Problem 1) To partition a set S into equivalent classes such that two members x and y of S are in the same equivalence class iff x y 2) Example 0 4, 3 1, 6 10, 8 9, 7 4, 6 8, 3 5, 2 11, 11 0 {0,2,4,7,11; {1,3,5; {6,8,9,10-41/60-
42 Equivalence Relations Algorithm Assume that m is the number of pairs, n is the number of objects void equivalence () { initialize seq to NULL and out to TRUE; while (there are more pairs) { read the next pair <i,j>; put j on the seq[i] list; put i on the seq[j] list; for (i = 0; i < n; i++) if (out[i]) { out[i] = FALSE; output this equivalence class; -42/60-
43 Example of Equivalence Relations 0 4, 3 1, 6 10, 8 9, 7 4, 6 8, 3 5, 2 11, 11 0 seq /60-
44 Implementation of Equivalence Relations (1/3) typedef struct node *node_pointer; typedef struct node { int data; node_pointer link; ; void main (void) { short int out[max_size]; node_pointer seq[max_size]; node_pointer x,y,top; int i,j,n; printf("enter the size (<= %d) ", MAX_ SIZE); scanf("%d", &n); for (i=0; i<n; i++) { out[i]=true; seq[i]=null; printf("enter a pair of numbers (-1-1 to quit): "); scanf("%d%d", &i, &j); -44/60-
45 Implementation of Equivalence Relations (2/3) /* phase 1: input the equivalence class */ while (i >= 0) { x = (node_pointer)malloc(sizeof(node)); if (IS_FULL(x)) { fprintf(stderr, "The memory is full\n"); exit(1); x->data = j; x->link = seq[i]; seq[i] = x; x = (node_pointer)malloc(sizeof(node)); if (IS _ FULL(x)) { fprintf(stderr, "The memory is full\n"); exit(1); x->data = i; x->link = seq[j]; seq[j] = x; printf("enter a pair of numbers (-1-1 to quit): "); scanf("%d%d", &i, &j); -45/60-
46 Implementation of Equivalence Relations (3/3) /* phase 2: print out the equivalent classes */ for (i = 0; i < n; i++) if (out[i]) { printf("\nnew class: %5d", i); out[i] = FALSE; x = seq[i]; top = NULL; for (;;) { while (x) { j = x->data; if (out[j]) { printf(%5d", j); out[j] = FALSE; y = x->link; x->link = top; top = x; x = y; else x = x->link; if (!top) break; x = seq[top->data]; top = top->link; -46/60-
47 Sparse Matrix Circular List Representation 1. Node structure typedef enum {head, entry tagfield; typedef struct matrix_node *matrix_pointer; typedef struct entry_node { int row; Head node int col; int value; ; typedef struct matrix_node { down right next 0 matrix_pointer down; matrix_pointer right; Entry node tagfield tag; union { down right 1 matrix_pointer next; entry_node entry; u; row col value ; -47/60-
48 Example of Circular Representation of Sparse Matrix hdnode[0] hdnode[1] hdnode[2] hdn ode[0] hdnode e[1] hdn node[2] /60-
49 Reading a Sparse Matrix (1/3) matrix_pointer hdnode[max_size]; matrix_pointer mread (void) { int num_rows, num_cols, num_terms, num_heads, i; int row, col, value, current_row; matrix_pointer temp,last,node; printf("enter the number of rows, columns, and number of nonzero terms: "); scanf("%d%d%d", &num_rows, &num_cols, &num_terms); num_heads = (num_cols > num_rows)? num_cols : num_rows; node = new_node(); node->tag = entry; node->u.entry.row = num_rows; node->u.entry.col = num cols; -49/60-
50 Reading a Sparse Matrix (2/3) if (!num_heads) node->right = node; else { for (i = 0; i < num_heads; i++) { temp = new_node(); hdnode[i] = temp; hdnode[i]->tag = head; hdnode[i]->right = temp; hdnode[i]->u.next = temp; current_row = 0; last = hdnode[0]; for (i = 0; i < num_terms; i++) { printf("enter row, column and value: "); scanf("%d%d%d", &row,&col,&value); if (row > current_row) { last->right t = hdnode[current e t_ row]; current_row = row; last = hdnode[row]; -50/60-
51 Reading a Sparse Matrix (3/3) temp = new_node(); temp->tag = entry; temp->u.entry.row = row; temp->u >u.entry.col = col; temp->u.entry.value = value; last->right = temp; last = temp; hdnode[col]->u.next->down=temp; >down temp; hdnode[col]->u.next = temp; last->right = hdnode[current _ row]; for (i = 0; i < num_cols; i++) hdnode[i]->u.next->down = hdnode[i]; for (i = 0; i < num_heads-1; i++) hdnode[i]->u.next = hdnode[i+1]; hdnode[num_heads-1]->u.next = node; node->right = hdnode[0]; return node; -51/60-
52 Writing a Sparse Matrix void mwrite (matrix_pointer *node) { int i; matrix_pointer temp, head = node->right; printf("\n num_rows = %d, num_cols = %d \n", node->u.entry.row, node->u.entry.col); printf(" The matrix by row, column, and value: \n\n"); for (i = 0; i < node->u.entry.row; i++) { for (temp = head->right; temp!= head; temp = temp->right){ printf("%5d%5d%5d \n", temp->u.entry.row, temp->u.entry.col, temp->u.entry.value); head = head->u.next; -52/60-
53 Writing a Sparse Matrix - Example hd dnode[0] hdnode e[1] hdno ode[2] /
54 Erasing a Sparse Matrix void merase (matrix_pointer *node) { matrix_pointer x,y, head = (*node)->right; int i, num_heads; /* free the entry and head nodes by row */ for (i = 0; i < (*node)->u.entry.row; i++) { y = head->right; while (y!= head) { x = y; y = y->right; free(x); x = head; head = head->u.next; free(x); /* free remaining head nodes */ y = head; while (y!= *node) { x = y; y = y->u.next; free(x); free(*node); *node = NULL; -54/60-
55 Erasing a Sparse Matrix - Example hdnode e[0] hdn node[1] hdnode[2 2] /60-
56 Doubly Linked Lists 1. Node structure typedef struct node *node_pointer; typedef struct node { node_pointer llink; element item; node_pointer rlink; ptr = ptr->llink->rlink l k = ptr->rlink->llink ll k ptr llink item rlink -56/60-
57 Doubly Linked Circular Lists (DLCL) 1. Doubly linked circular list with head nodes Head node list_head llink item rlink 2. Empty list list_head -57/60-
58 Inserting a Node to a DLCL list_head a b c d void dinsert (node_pointer node, node_pointer newnode) { /* insert newnode to the right of the node */ newnode->llink = node; newnode->rlink = node->rlink; node->rlink->llink = newnode; node->rlink = newnode; -58/60-
59 Deleting a Node from DLCL list_head a b c void ddelete (node_p pointer node, node_pointer deleted) { /* delete from the DLCL pointed to by node */ if (node == deleted) printf("deletion of head node not permitted.\n"); else { deleted->llink->rlink = deleted->rlink; deleted->rlink->llink = deleted->link; free(deleted); -59/60-
60 1. Singly linked list 1) Stack 2) Queue 3) Polynomials 4) Equivalence class 2. Circularly linked list 1) Polynomials l 2) Sparse matrix Summary 3. Doubly linked circular list 1) Insertion 2) Deletion -60/60-
Chapter 4. LISTS. 1. Pointers
Chap 4: LIST (Page 1) Chapter 4. LISTS TABLE OF CONTENTS 1. POINTERS 2. SINGLY LINKED LISTS 3. DYNAMICALLY LINKED STACKS AND QUEUES 4. POLYNOMIALS 5. ADDITIONAL LIST OPERATIONS 6. EQUIVALENCE RELATIONS
More informationIntroduction. Array successive items locate a fixed distance disadvantage. possible solution
CHAPTER 4 LISTS All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed Fundamentals of Data Structures in C, CHAPTER 4 1 Introduction Array successive items
More informationIntroduction. Array successive items locate a fixed distance disadvantage. possible solution
CHAPTER 4 LISTS All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed Fundamentals of Data Structures in C, CHAPTER 4 1 Introduction Array successive items
More informationMODULE 3: LINKED LIST
MODULE 3: LINKED LIST DEFINITION A linked list, or one-way list, is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. That is, each node is divided
More informationPointers. Array. Solution to the data movement in sequential representation
1 LISTS Pointers Array sequential representation some operation can be very time-consuming (data movement) size of data must be predefined static storage allocation and deallocation Solution to the data
More informationData Structure. Chapter 4 List (Part II) Department of Communication Engineering National Central University Jhongli, Taiwan.
Data Structure Chapter 4 List (Part II) Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2009 Spring Outline Polynomials Sparse matrices Doubly linked
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 10: Implementation of Linked Lists (Linked stacks and queues, Circular linked lists) 2015-2016 Fall Linked list implementation of stacks The cost of insert and delete at
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 10: Implementation of Linked Lists (Stacks, Queue, Hashtable) 2017-2018 Fall Linked list implementation of stacks The cost of insert and delete at the beginning of a linked
More informationFall, 2015 Prof. Jungkeun Park
Data Structures t and Algorithms Circular lists / Doubly linked lists Fall, 2015 Prof. Jungkeun Park Copyright Notice: This material is modified version of the lecture slides by Prof. Rada Mihalcea in
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering
USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering SOLUTION FOR INTERNAL ASSESSMENT TEST 2 Date : 6/10/2017 Marks:
More information國立清華大學電機工程學系. Outline
國立清華大學電機工程學系 EE2410 Data Structure Chapter 4 Linked List (Part II) Outline Equivalence Class Sparse Matrices Doubly Linked Lists Generalized Lists Virtual Functions and Dynamic Binding ch4.2-2 1 Equivalence
More informationData Structure - Skip List etc. -
Data Structure - Skip List etc. - Hanyang University Jong-Il Park SKIP LIST Introduction to Skip Lists An interesting generalization of linked lists for dictionary ADT. Keep the simplicity of linked lists
More informationWhy circular list? check whether a pointer current points to the last node. check for (current->link == first)
4.4 Circular lists Why circular list? check whether a pointer current points to the last node check for (current->link == first) circular list 를사용하는이유 : Figure 4.13(section 4.7.3: circular list representation
More informationLinked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra
Linked List in Data Structure By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List Like arrays, Linked List is a linear data
More informationSolution for Data Structure
Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT
More informationAshish Gupta, Data JUET, Guna
Categories of data structures Data structures are categories in two classes 1. Linear data structure: - organized into sequential fashion - elements are attached one after another - easy to implement because
More informationCHAPTER 4 LINKED LISTS
CHAPTER 4 LINKED LISTS Iris Hui-Ru Jiang Fall 2008 2 Contents Array vs. list Singly linked lists Doubly linked lists Applications Readings Chapter 4 C++ STL list iterators iterator, const_iterator reverse_iterator,
More informationLists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues
(Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues By: Pramod Parajuli, Department of Computer Science, St. Xavier
More informationThat means circular linked list is similar to the single linked list except that the last node points to the first node in the list.
Leaning Objective: In this Module you will be learning the following: Circular Linked Lists and it operations Introduction: Circular linked list is a sequence of elements in which every element has link
More informationChapter 2 Arrays and Structures
Data Structure Chapter 2 Arrays and Structures Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2 Spring Outline Array Structures Polynomial Sparse
More informationChapter 4 Linked Lists(Part II)
Chapter 4 Linked Lists(Part II) Equivalence Class Sparse Matrices Doubly Linked Lists Generalized Lists Virtual Functions & Dynamic Binding Heterogeneous Lists Linked List II-1 Equivalence Relation A relation
More informationBinary Trees. Height 1
Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.
More informationChapter 4 Linked Lists(Part I) Singly linked lists A reusable linked list Class Circular Lists Linked stacks & queues Polynomials
Chapter 4 Linked Lists(Part I) Singly linked lists A reusable linked list Class Circular Lists Linked stacks & queues Polynomials Link List I-1 Introduction Why Linked List? Array successive items locate
More informationThe combination of pointers, structs, and dynamic memory allocation allow for creation of data structures
Data Structures in C C Programming and Software Tools N.C. State Department of Computer Science Data Structures in C The combination of pointers, structs, and dynamic memory allocation allow for creation
More informationLinked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
1 Linked Lists.. and other linked structures Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Dynamic memory allocation: review typedef struct { int hitemp;
More informationDynamic Memory Allocation and Linked Lists
CSE 2421: Systems I Low-Level Programming and Computer Organization Dynamic Memory Allocation and Linked Lists Presentation I Read/Study: Reek Chapter 11 & 12 Gojko Babić 02-26-2017 Functions malloc and
More informationActually, C provides another type of variable which allows us to do just that. These are called dynamic variables.
When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called
More informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours
TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART
More informationIntroduction to Data Structures. Systems Programming
Introduction to Data Structures Systems Programming Intro to Data Structures Self-referential Structures Dynamic Memory Allocation A Simple malloc Example Linear Lists Linked Lists Insertion Example Linked
More informationStack & Queue on Self-Referencing Structures
C Programming 1 Stack & Queue on Self-Referencing Structures C Programming 2 Representation of Stack struct stack { int data ; struct stack *next ; ; typedef struct stacknode node, *stack ; C Programming
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 LINKED LISTS LINKED LIST What are the problems with arrays? üsize is fixed üarray items are stored contiguously üinsertions and deletions at particular positions is complex
More informationLinked List. April 2, 2007 Programming and Data Structure 1
Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element
More informationChapter 17: Linked Lists
Chapter 17: Linked Lists 17.1 Introduction to the Linked List ADT Introduction to the Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures list head
More informationStack & Queue on Self-Referencing Structures
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 Stack & Queue on Self-Referencing Structures PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Representation of Stack struct stack { int data ; struct
More informationDC54 DATA STRUCTURES DEC 2014
Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as
More informationDC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link
More informationMODULE V: POINTERS & PREPROCESSORS
MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) An interesting definition for stack element The stack element could be of any data type struct stackelement int etype; union int ival;
More informationDarshan Institute of Engineering & Technology for Diploma studies Unit 4
Pointer A pointer is a variable that contains address or location of another variable. Pointer is a derived data type in C. Pointers contain memory address as their values, so they can also be used to
More informationMTH 307/417/515 Final Exam Solutions
MTH 307/417/515 Final Exam Solutions 1. Write the output for the following programs. Explain the reasoning behind your answer. (a) #include int main() int n; for(n = 7; n!= 0; n--) printf("n =
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) The queue ADT A queue is like a "natural" queue of elements. It is an ordered list in which all insertions occur at one end called
More informationData Structures & Algorithm Analysis. Lecturer: Souad Alonazi
Data Structures & Algorithm Analysis Lec(3) Stacks Lecturer: Souad Alonazi What is a stack? Stores a set of elements in a particular order Stack principle: LAST IN FIRST OUT = LIFO It means: the last element
More informationAdvantage of an array ADT:
Data Structures using C Chapter-2 ARRAYS AND SRUCTURES Array an array is a set of pairs, , such that each index that is defined has a value associated with it a consecutive set of memory
More informationQueues. Manolis Koubarakis. Data Structures and Programming Techniques
Queues Manolis Koubarakis 1 The ADT Queue A queue Q of items of type T is a sequence of items of type T on which the following operations are defined: Initialize the queue to the empty queue. Determine
More informationAPS105. Structures 11/18/2013. Example A struct of stock items at a store: Structures. Lists. Arrays allow a collection of elements
APS105 Lists Structures Textbook Chapters 10.1, 10.3, 10.4, 10.6 2 Structures Arrays allow a collection of elements All of the same type How to collect elements of different types? Structures; in C: struct
More informationCHAPTER 5. Trees CHAPTER 5 1/70
CHAPTER 5 Trees All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed Fundamentals of Data Structures in C /2nd Edition, Silicon Press, 2008. CHAPTER 5
More informationAnswer all questions. Write your answers only in the space provided. Full marks = 50
Answer all questions. Write your answers only in the space provided. Full marks = 50 1. Answer the following: [2+3+2+1=8 marks] a) What are the minimum and maximum numbers that can be represented in 10-bit
More informationUNIT-2 Stack & Queue
UNIT-2 Stack & Queue 59 13. Stack A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards
More informationUNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.
UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation
More informationModule III. Linear Data Structures and their Linked Storage Representation
Module III Linear Data Structures and their Linked Storage Representation 3.1 Linked List Linked list is the collection of inter connected nodes with a head node representing the first node and a tail
More informationData Structure and Algorithm Homework #2
Data Structure and Algorithm Homework #2 === Homework Reference Solution === Problem 1. Transfer a letter We can use the following structure to represent our list. struct Node{ char word[50]; struct Node
More information/* Polynomial Expressions Using Linked List*/ #include<stdio.h> #include<conio.h> #include <malloc.h> struct node. int num; int coeff;
/* Polynomial Expressions Using Linked List*/ #include #include #include struct node int num; int coeff; struct node *next; ; struct node *start1 = NULL; struct node *start2
More informationCS32 Discussion Week 3
CS32 Discussion Week 3 Muhao Chen muhaochen@ucla.edu http://yellowstone.cs.ucla.edu/~muhao/ 1 Outline Doubly Linked List Sorted Linked List Reverse a Linked List 2 Doubly Linked List A linked list where
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may
More informationThis document can be downloaded from with most recent updates. 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS
1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS 4.1 MEMORY MANAGEMENT 4.1.1 Basics about Memory When a C program is compiled, the compiler translates the source code into machine code. Now the
More informationChapter 17: Linked Lists
Chapter 17: Linked Lists Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 17.1 Introduction to the
More informationESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists
ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees Instructor: Krithika Venkataramani Semester 2, 2011-2012 1 Introduction to Linked Lists Each bead connected to the next through a
More informationChapter 6. GRAPHS. Figure 6.1 : The bridges of Koenigsberg
Chap : Graphs (Page ) Chapter. GRAPHS. THE GRAPH ABSTRACT DATA TYPE. ELEMENTARY GRAPH OPERATIONS. MINIMUM COST SPANNING TREES. SHORTEST PATHS AND TRANSITIVE CLOSURE. ACTIVITY NETWORKS Chap : Graphs (Page
More informationQueues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1
Queues October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queue ADT Queue ADT should support at least the first two operations: enqueue insert an item to the back of the queue dequeue remove an item from
More informationCSE2301. Dynamic memory Allocation. malloc() Dynamic Memory Allocation and Structs
Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who
More informationData Structure. Chapter 5 Trees (Part II) Angela Chih-Wei Tang. National Central University Jhongli, Taiwan
Data Structure Chapter 5 Trees (Part II) Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2010 Spring Threaded Binary Tree Problem: There are more
More informationINDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator EXAMINATION ( End Semester ) SEMESTER ( Autumn ) Roll Number Section Name Subject Number C S 1 1 0 0 1 Subject Name Programming
More information1 SAT-DANCE-HEULE INTRO 1
1 SAT-DANCE-HEULE INTRO 1 May 19, 2018 at 02:31 1. Intro. Given an exact cover problem, presented on stdin in the format used by DANCE, we generate clauses for an equivalent satisfiability problem in the
More informationC Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function
More informationApplied Programming and Computer Science, DD2325/appcs14 PODF, Programmering och datalogi för fysiker, DA7011
Applied Programming and Computer Science, DD2325/appcs14 PODF, Programmering och datalogi för fysiker, DA7011 Lecture 4, C programming: pointer, array, struct, list A. Maki, C. Edlund November 2014 Pointer
More informationCOP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME
CLOSED BOOK Exam #1 100 Points NAME 1. The following program has (at least) 10 syntax errors. Circle each error. Write the corrected program in the blank space below. 2 points for each error you find.
More informationReview of Data Structure(I)
Review of Data Structure(I) Ch. Basic Concepts: Pointers and dynamic memory allocation, data abstraction, algorithm specification, performance analysis & measurement Ch. Arrays and Structures: Dynamically
More informationCS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type
More information(6-1) Basics of a Queue. Instructor - Andrew S. O Fallon CptS 122 (September 26, 2018) Washington State University
(6-1) Basics of a Queue Instructor - Andrew S. O Fallon CptS 122 (September 26, 2018) Washington State University What is a Queue? 2 A linear data structure with a finite sequence of nodes, where nodes
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationData Structure. Chapter 3 Stacks and Queues. Department of Communication Engineering National Central University Jhongli, Taiwan.
Data Structure Chapter 3 Stacks and Queues Instructor: Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 29 Spring Outline Stack Queue A Mazing Problem
More informationINDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator EXAMINATION ( End Semester ) SEMESTER ( Spring ) Roll Number Section Name Subject Number C S 1 0 0 0 1 Subject Name Programming
More informationNow consider the following situation after deleting three elements from the queue...
Scheme of valuvation -1I Subject & Code : Data Structure and Application (15CS33) NOTE: ANSWER All FIVE QUESTIONS 1 Explain the diadvantage of linear queue and how it i olved in circular queue. Explain
More informationLinked List using a Sentinel
Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include
More informationChapter 9 STACK, QUEUE
Chapter 9 STACK, QUEUE 1 LIFO: Last In, First Out. Stacks Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP. Stack
More informationClass Information ANNOUCEMENTS
Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to
More informationLecture Notes CPSC 122 (Fall 2014) Today Quiz 7 Doubly Linked Lists (Unsorted) List ADT Assignments Program 8 and Reading 6 out S.
Today Quiz 7 Doubly Linked Lists (Unsorted) List ADT Assignments Program 8 and Reading 6 out S. Bowers 1 of 11 Doubly Linked Lists Each node has both a next and a prev pointer head \ v1 v2 v3 \ tail struct
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationLinked Lists Structures
Linked Lists Structures 1. Motivation... 2 2. Declaration of a node... 3 2.1. Operations on pointers:... 4 2.2. Disposition of a node... 5 2.3. Singly Linked Lists... 5 3. One-way linked lists... 6 3.1.
More informationCpt S 122 Data Structures. Data Structures
Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation
More informationCT11 (ALCCS) DATA STRUCTURE THROUGH C JUN 2015
Solutions Q.1 a. What is a pointer? Explain how it is declared and initialized. (4) Different from other normal variables which can store values, pointers are special variables that can hold the address
More informationOutline. Briefly review the last class Pointers and Structs Memory allocation Linked lists
Outline Briefly review the last class Pointers and Structs Memory allocation Linked lists C Structures and Memory Allocation A struct is a data structure that comprises multiple types, each known as a
More informationFundamentals of Programming & Procedural Programming
Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Eight: Math Functions, Linked Lists, and Binary Trees Name: First Name: Tutor:
More informationProcedural Programming
Exercise 6 (SS 2016) 04.07.2015 What will I learn in the 6. exercise Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Home exercise 4 (3 points) Write a program which is able to handle
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationBentley Rules for Optimizing Work
6.172 Performance Engineering of Software Systems SPEED LIMIT PER ORDER OF 6.172 LECTURE 2 Bentley Rules for Optimizing Work Charles E. Leiserson September 11, 2012 2012 Charles E. Leiserson and I-Ting
More informationData Structure Series
Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after
More informationAdvanced Programming. Lists. A list is a data structure based on usage of pointers and dynamic allocation of memory.
Intro A list is a data structure based on usage of pointers and dynamic allocation of memory. With respect to other ADT (like arrays), a list: provides more flexibility in memory usage but it is less efficient.
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 15, 2014 9:30 a.m. 12:00 p.m. (150 minutes) Examiners: B. Li, J. Rose, H. Timorabadi,
More informationWrite a C program to add two Complex numbers using functions illustrating-
Scheme of valuvation Date : 29/8/2017 Marks: 40 Subject & Code : Data Structures and Applications (15CS33) Class : III A&B Name of Faculty : Ms. Saritha Time : 8:30 am to 10 am NOTE: ANSWER All FIVE QUESTIONS
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more
More informationLinked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list
Linked Lists Introduction : Data can be organized and processed sequentially using an array, called a sequential list Problems with an array Array size is fixed Unsorted array: searching for an item is
More informationLinked Lists in C and C++
Linked Lists in C and C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by
More informationLinked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list
Linked Lists Introduction : Data can be organized and processed sequentially using an array, called a sequential list Problems with an array Array size is fixed Unsorted array: searching for an item is
More informationBITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER
BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2017-2018 COURSE : COMPUTER PROGRAMMING (CS F111) COMPONENT : Tutorial# 7 (SOLUTIONS) DATE : 06-DEC-2017 Answer 1 enum
More informationChapter 6. Data Structure. /* start contains the address of the first node */ start = &elephant1; print_elephants( start ); return EXIT_SUCCESS;
Chapter 6 Data Structure Introductory notes are included in PowerPoint file. The programs illustrated are as follows: //elephnt1.c // This example is from C for Scientists and Engineers #include
More informationProcedural programming with C
Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical
More informationA. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS
Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA
USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT TEST 2 (Scheme and Solution) Data Structures Using C (16MCA11) 1) A.
More informationP.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above
P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above
More information