Pointers. Array. Solution to the data movement in sequential representation

Size: px
Start display at page:

Download "Pointers. Array. Solution to the data movement in sequential representation"

Transcription

1 1 LISTS

2 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 movement in sequential representation pointers: often called links 2

3 Pointers For any type T in C, there is corresponding type pointerto-t Actual value of pointer type : an address of memory Pointer operators in C the address operator : & the dereferencing(or indirection) operator : * 3

4 Pointers Dynamically allocated storage C provides a mechanism, called a heap, for allocating storage at run-time int i,*pi; float f,*pf; pi = (int *)malloc(sizeof(int)); pf = (float *)malloc(sizeof(float)); *pi = 1024; *pf = 3.14; printf( an integer=%d,a float=%f\n,*pi,*pf); free(pi); free(pf); 4

5 Singly Linked Lists Composed of data part and link part link part contains address of the next element in a list non-sequential representations size of the list is not predefined dynamic storage allocation and deallocation ptr bat cat sat vat NULL 5

6 Singly Linked Lists To insert mat between cat and sat ptr bat cat sat vat NULL mat 1) get a node currently unused(paddr) 2) set the data of this node to mat 3) set paddr s link to point to the address found in the link of the node cat 4) set the link of the node cat to point to paddr Caution) step 3 must be done before step 4 6

7 Singly Linked Lists To delete mat from the list ptr bat cat mat sat vat NULL 1) find the element that immediately precedes mat, which is cat 2) set its link to point to mat s link No data movement in insert and delete operations 7

8 Singly Linked Lists Required capabilities to make linked representations possible a mechanism for defining a node s structure, that is, the field it contains a way to create new nodes when we need them a way to remove nodes that we no longer need 8

9 Singly Linked Lists Ex 4.1 [list of words ending in at ] Define a node structure for the list data field: character array link field: pointer to the next node self-referential structure typedef struct list_node *list_ptr; typedef struct list_node { char data[4]; list_ptr link; ; list_ptr ptr = NULL; 9

10 Singly Linked Lists Create new nodes for our list Then place the word bat into our list ptr=(list_ptr)malloc(sizeof(list_node)); strcpy(ptr->data, bat ); ptr->link=null; address of first node ptr->data ptr->link b a t \0 NULL ptr 10

11 Singly Linked Lists Ex 4.2 [two-node linked list] Create a linked list of integers typedef struct list_node *list_ptr; typedef struct list_node { int data; list_ptr link; ; list_ptr ptr = NULL; ptr NULL 11

12 Singly Linked Lists list_ptr create2() { list_ptr first, second; first = (list_ptr)malloc(sizeof(list_node)); second = (list_ptr)malloc(sizeof(list_node)); second->link=null; second->data=20; first->data=10; first->link=second; return first; 12

13 Singly Linked Lists Ex 4.3 [list insertion] ptr NULL node 50 temp Determine if we have used all available memory: IS_FULL 13

14 Singly Linked Lists void insert(list_ptr *pptr, list_ptr node) { list_ptr temp; temp=(list_ptr)malloc(sizeof(list_node)); if(is_full(temp)) { fprintf(stderr, The momory is full\n ); exit(1); temp->data=50; if(*pptr) { temp->link = node->link; node->link = temp; else { temp->link = NULL; *pptr = temp; 14

15 Singly Linked Lists Ex 4.4 [list deletion] Deletion depends on the location of the node: more complicated Assumption ptr: point to the start of list node: point to the node to be deleted trail: point to the node that precedes node to be deleted 15

16 Singly Linked Lists 1) the node to be deleted is the first node in the list ptr node trail = NULL ptr NULL NULL 2) otherwise (a) before deletion (b) after deletion ptr trail node ptr NULL NULL (a) before deletion (b) after deletion 16

17 Singly Linked Lists void delete(list_ptr *pptr, list_ptr trail, list_ptr node) { if(trail) trail->link = node->link; else *pptr = (*pptr)->link; free(node); 17

18 Singly Linked Lists Ex 4.5 [printing out a list] while not end of the list do print out data field; move to the next node; end; void print_list(list_ptr ptr) { printf( The list contains: ); for(; ptr; ptr = ptr->link) printf( %4d, ptr->data); printf( \n ); 18

19 Dynamically Linked Stacks Representing stack / queue by linked list top element link NULL (a) linked stack front rear element link NULL (b) linked queue 19

20 Dynamically Linked Stacks Representing N stacks by linked lists #define MAX_STACKS 10 /* N=MAX_STACKS=10 */ typedef struct { int key; /* other fields */ element; typedef struct stack *stack_ptr; typedef struct stack { element item; stack_ptr link; ; stack_ptr top[max_stacks]; 20

21 Dynamically Linked Stacks top[0] element link key NULL top[1] NULL top[max_stacks-1] NULL 21

22 Dynamically Linked Stacks Initial condition for stacks top[i] = NULL, 0 i < MAX_STAKCS Boundary condition for n stacks Empty condition: top[i] = NULL iff the i-th stack is empty Full condition: IS_FULL(temp) iff the memory is full 22

23 Dynamically Linked Stacks Add to a linked stack void push(stack_ptr *ptop, element item) { stack_ptr temp = (stack_ptr)malloc(sizeof (stack)); if(is_full(temp)) { fprintf(stderr, The memory is full\n ); exit(1); temp->item=item; temp->link=*ptop; *ptop = temp; 23

24 Dynamically Linked Stacks Delete from a linked stack element pop(stack_ptr *ptop) { stack_ptr temp = *ptop; element item; if(is_empty(temp)) { fprintf(stderr, The stack is empty\n ); exit(1); item=temp->item; *ptop=temp->link; free(temp); return item; 24

25 Dynamically Linked Queues Representing M queues by linked lists #define MAX_QUEUES 10 /* M=MAX_QUEUES=10 */ typedef struct queue *queue_ptr; typedef struct queue { element item; queue_ptr link; ; queue_ptr front[max_queues],rear[max_queues]; 25

26 Dynamically Linked Queues front[0] rear[0] element link key NULL front[1] rear[1] NULL front[max_queues-1] rear[max_queues-1] NULL 26

27 Dynamically Linked Queues Initial conditon for queues front[i]=null,0 i < MAX_QUEUES Boundary condition for queues Empty condition: front[i]= NULL iff the i-th queue is empty Full condition: IS_FULL(temp) iff the memory is full 27

28 Dynamically Linked Queues Add to the rear of a linked queue void insert(queue_ptr *pfront, queue_ptr *prear, element item) { queue_ptr temp = (queue_ptr)malloc(sizeof(queue)); if(is_full(temp)) { fprintf(stderr, The memory is full\n ); exit(1); temp->item=item; temp->link=null; if (*pfront) (*prear)->link=temp; else *pfront = temp; *prear = temp; 28

29 Dynamically Linked Queues Delete from the front of a linked queue element delete(queue_ptr *pfront) { queue_ptr temp=*pfront; element item; if (IS_EMPTY(*front)) { fprintf(stderr, The queue is empty\n ); exit(1); item=temp->item; *pfront=temp->link; free(temp); return item; 29

30 Dynamically Linked Stacks And Queues Representing stacks/queues by linked lists no data movement is necessary : O(1) no full condition check is necessary size is growing and shrinking dynamically 30

31 Polynomials Representing polynomials as singly linked lists A(x) = a m-1 x e m a 0 x e 0 typedef struct poly_node *poly_ptr; typedef struct poly_node { int coef; int expon; poly_ptr link; ; poly_ptr a,b,d; 31

32 Polynomials poly_node a = 3x x a coef expon link NULL b = 8x 14-3x x 6 b NULL 32

33 Polynomials Adding polynomials NULL a NULL b NULL d rear (a) a->expon == b->expon 33

34 Polynomials NULL a NULL b NULL d rear (b) a->expon < b->expon 34

35 Polynomials NULL a NULL b NULL d (c) a->expon > b->expon rear 35

36 Polynomials NULL NULL a b d 10 6 NULL rear (d) a->expon < b->expon 36

37 Polynomials NULL NULL a b d NULL (e) b == NULL; rear 37

38 Polynomials poly_ptr padd(poly_ptr a,poly_ptr b) { poly_ptr front,rear,temp; int sum; rear=(poly_ptr)malloc(sizeof(poly_node)); if(is_full(rear)) { fprintf(stderr, The memory is full\n ); exit(1); front = rear; (to be continued) 38

39 Polynomials 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 = b->link; break; case 1: /* a->expon > b->expon */ attach(a->coef,a->expon,&rear); a = a->link; (to be continued) 39

40 Polynomials 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; temp=front; front=front->link; free(temp); return front; 40

41 Polynomials Function attach() to create a new node and append it to the end of d void attach(float coe,int exp,poly_ptr *pptr) { poly_ptr temp; temp=(poly_ptr)malloc(sizeof(poly_node)); if(is_full(temp)) { fprintf(stderr, The memory is full\n ); exit(1); temp->coef = coe; temp->expon = exp; (*pptr)->link = temp; *pptr=temp; 41

42 Polynomials Analysis of padd where m, n : number of terms in each polynomial coefficient additions: O(min{m, n) exponent comparisons: O(m + n) creation of new nodes for d: O(m + n) Time complexity: O(m + n) 42

43 Polynomials Erasing polynomials void erase(poly_ptr *pptr) { poly_ptr temp; while (*pptr) { temp = *pptr; *pptr = (*pptr)->link; free(temp); Useful to reclaim the nodes that are being used to represent partial result such as temp(x) 43

44 Polynomials Allocating/deallocating nodes How to preserve free node in a storage pool? initially link together all free nodes into a list in a storage pool avail: variable of type poly_ptr that points to the first node in list of freed nodes storage pool 1 2 n avail NULL initial available space list 44

45 Polynomials Allocating nodes poly_ptr get_node(void) { poly_ptr node; if (avail) { node = avail; avail = avail->link; else { node = (poly_ptr)malloc(sizeof(poly_node)); if (IS_FULL(node)) { fprintf(stderr, The memory is full\n ); exit(1); return node; 45

46 Polynomials Deallocating nodes void ret_node(poly_ptr ptr) { ptr->link = avail; avail = ptr; void erase(poly_ptr *pptr) { poly_ptr temp; while (*pptr) { temp = *pptr; *pptr = (*pptr)->link; ret_node(temp); 46

47 Polynomials Traverse to the last node in the list: O(n), where n: number of terms How to erase polynomial efficiently? How to return n used nodes to storage pool? 47

48 Polynomials Representing polynomials as circularly linked list to free all the node of a polynomial more efficiently modify list structure the link of the last node points to the first node in the list called circular list ( chain) ptr 48

49 Polynomials Maintain our own list (as a chain) of nodes that has been freed obtain effective erase algorithm void cerase(poly_ptr *pptr) { if (*pptr) { temp = (*pptr)->link; (*pptr)->link = avail; avail = temp; *pptr = NULL; Independent on the number of nodes in a list: O(1) 49

50 Polynomials Circular list with head nodes handle zero polynomials in the same way as nonzero polynomials ptr - - head node (empty list) ptr - - head node 50

51 Operations for Chains Inverting(or reversing) a chain in place by using three pointers : lead, middle, trail typedef struct list_node *list_ptr; typedef struct list_node { ; char data; list_ptr link; 51

52 Operations for Chains Inverting a chain list_ptr invert(list_ptr lead) { list_ptr middle, trail; middle = NULL; while(lead) { trail = middle; middle = lead; lead = lead->link; middle->link = trail; return middle; time: O(length) 52

53 Operations for Chains middle lead NULL NULL trail middle lead NULL NULL 53 trail middle lead

54 Operations for Chains NULL NULL trail middle lead NULL NULL trail middle lead NULL NULL 54 trail middle lead

55 Operations for Chains Concatenate two chains Produce a new list that contains ptr1 followed by ptr2 list_ptr concat(list_ptr ptr1,list_ptr ptr2) { list_ptr 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; 55

56 Operations for Chains Finding the length of a list(chain) int length(list_ptr ptr) { int count = 0; while (ptr) { count++; ptr = ptr->link; return count; 56

57 Operations for Chains Insert a new node at the front or at the rear of the chain ptr x1 x2 x3 NULL move down the entire length of ptr to insert rear: front-insert : O(1) rear-insert : O(n) 57

58 Operations for Chains Insert a new node at the front of a list(chain) void insert_front(list_ptr *pptr, list_ptr node) { if (IS_EMPTY(*pptr)) { *pptr = node; node->link = NULL; else { node->link = *pptr; *pptr = node; 58

59 Operations for Circularly Linked Lists (singly) circularly linked lists ptr x1 x2 x3 insert a new node at the front or at the rear move down the entire length of ptr to insert both front and rear: insert-front : O(n) insert-rear : O(n) 59

60 Operations for Circularly Linked Lists Improve this better: make ptr points to the last node Insert a new node at the front or at the rear front-insert : O(1) rear-insert : O(1) x1 x2 x3 ptr 60

61 Operations for Circularly Linked Lists Insert a new node at the rear of a circular list void insert_rear(list_ptr *pptr, list_ptr node) { if (IS_EMPTY(*pptr)) { *pptr = node; node->link = node; else { node->link = (*pptr)->link; (*pptr)->link = node; *pptr = node; /* for front-insert, remove this line */ 61

62 Operations for Circularly Linked Lists Finding the length of a circular list int length(list_ptr ptr) { list_ptr temp; int count = 0; if (ptr) { temp = ptr; do { count++; temp = temp->link; while (temp!= ptr); return count; 62

63 Doubly linked lists Problems of singly linked lists move to only one way direction hard to find the previous node hard to delete the arbitrary node because finding the previous node is hard Doubly linked circular list doubly lists + circular lists allow two links two way direction 63

64 Doubly linked lists typedef struct node *node_ptr; typedef struct node { ; node_ptr llink; element item; node_ptr rlink; Suppose that ptr points to any node in a doubly linked list ptr = ptr->llink->rlink = ptr->rlink->llink 64

65 Doubly linked lists Introduce dummy node, called, head to represent empty list make easy to implement operations contains no information in item field empty doubly linked circular list with head node ptr 65

66 Doubly linked lists head node llink item rlink doubly linked circular list with head node 66

67 Doubly linked lists Insertion into a doubly linked circular list void dinsert(node_ptr node,node_ptr newnode) { /* insert newnode to the right of node */ newnode->llink = node; newnode->rlink = node->rlink; node->rlink->llink = newnode; node->rlink = newnode; time: O(1) 67

68 Doubly linked lists node node newnode insertion into an empty doubly linked circular list 68

69 Doubly linked lists Deletion from a doubly linked circular list void ddelete(node_ptr node,node_ptr deleted) { /* delete from the doubly linked list */ if (node == deleted) else { printf( Deletion of head node not permitted.\n ); deleted->llink->rlink = deleted->rlink; deleted->rlink->llink = deleted->llink; free(deleted); time complexity : O(1) 69

70 Doubly linked lists node node deleted deletion in a doubly linked list with a single node 70

71 Doubly linked lists Doubly linked circular list don t have to traverse a list : O(1) insert(delete) front/middle/rear is all the same 71

Chapter 4. LISTS. 1. Pointers

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 information

Chapter 4: Lists 2004 년가을학기. 강경란 정보및컴퓨터공학부, 아주대학교

Chapter 4: Lists 2004 년가을학기. 강경란 정보및컴퓨터공학부, 아주대학교 Chapter 4: Lists 2004 년가을학기 강경란 korykang@ajou.ac.kr 정보및컴퓨터공학부, 아주대학교 1. Pointers 2. Singly Linked Lists Chapter 4 Lists 3. Dynamically Linked Stacks and Queues 4. Polynomials 5. Additional List Operations

More information

BBM 201 DATA STRUCTURES

BBM 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 information

Data Structure. Chapter 4 List (Part II) Department of Communication Engineering National Central University Jhongli, Taiwan.

Data 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 information

BBM 201 DATA STRUCTURES

BBM 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 information

Fall, 2015 Prof. Jungkeun Park

Fall, 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 information

MODULE 3: LINKED LIST

MODULE 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 information

Introduction. Array successive items locate a fixed distance disadvantage. possible solution

Introduction. 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 information

Introduction. Array successive items locate a fixed distance disadvantage. possible solution

Introduction. 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 information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

PESIT 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

Chapter 17: Linked Lists

Chapter 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 information

Ashish Gupta, Data JUET, Guna

Ashish 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 information

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

Actually, 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 information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked 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 information

CHAPTER 4 LINKED LISTS

CHAPTER 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 information

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 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 information

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

The 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 information

Introduction to Data Structures. Systems Programming

Introduction 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 information

Chapter 17: Linked Lists

Chapter 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 information

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first Linked Lists Introduction to Linked Lists A data structure representing a Week 8 Gaddis: Chapter 17 CS 5301 Spring 2014 Jill Seaman A series of dynamically allocated nodes chained together in sequence

More information

Data Structure with C. List

Data Structure with C. List Subject: Data Structure with C Topic: List Introduction list is a finite sequence of data items, i.e. a collection of data items arranged in a certain linear order. he basic operations performed on this

More information

Data Structure Series

Data 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 information

The time and space are the two measure for efficiency of an algorithm.

The time and space are the two measure for efficiency of an algorithm. There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE 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 information

Darshan Institute of Engineering & Technology for Diploma studies Unit 4

Darshan 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 information

Chapter 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 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 information

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Linked 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 information

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Linked 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 information

1.1 Basic Concepts 1

1.1 Basic Concepts 1 1.1 Basic Concepts 1 What is Data Structure? (1) Data Structure How do we store (input/output) data in a (mostly) main memory? Ex) How to store a Matrix in a memory? We need to specify a data structure

More information

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Lists (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 information

CP2 Revision. theme: dynamic datatypes & data structures

CP2 Revision. theme: dynamic datatypes & data structures CP2 Revision theme: dynamic datatypes & data structures structs can hold any combination of datatypes handled as single entity struct { }; ;

More information

Dynamic Memory Allocation and Linked Lists

Dynamic 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 information

Solution for Data Structure

Solution 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 information

DC54 DATA STRUCTURES DEC 2014

DC54 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 information

MODULE 5: Pointers, Preprocessor Directives and Data Structures

MODULE 5: Pointers, Preprocessor Directives and Data Structures MODULE 5: Pointers, Preprocessor Directives and Data Structures 1. What is pointer? Explain with an example program. Solution: Pointer is a variable which contains the address of another variable. Two

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/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 information

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first Ch. 17: Linked Lists 17.1 Introduction to Linked Lists! A data structure representing a list! A series of nodes chained together in sequence CS 2308 Spring 2013 Jill Seaman - Each node points to one other

More information

This document can be downloaded from with most recent updates. 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS

This 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 information

國立清華大學電機工程學系. Outline

國立清華大學電機工程學系. 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 information

Ch. 17: Linked Lists. Introduction to Linked Lists

Ch. 17: Linked Lists. Introduction to Linked Lists Ch. 17: Linked Lists Part 1 CS 2308 Fall 2011 Jill Seaman Lecture 16 Using content from textbook slides: Starting Out with C++, Gaddis, Pearson/Addison-Wesley 1 Introduction to Linked Lists A data structure

More information

UNIT IV 4 LINKED LIST

UNIT IV 4 LINKED LIST 4 UNIT IV LINKED LIST LINKED LIST SYLLABUS: 4.1 Pointers Revision 4.2 Revision of Structure 4.3 Revision of structure using pointers 4.4 Dynamic Memory Allocation 4.5 Linked list Presentation 4.6 Types

More information

Linked Lists and other Dynamic Data Structures

Linked Lists and other Dynamic Data Structures Linked Lists and other Dynamic Data Structures Arrays Fixed in size Allocated in advance within a contiguous memory block Look-up is fast Resizing and Deleting is hard (reallocate and copy) Dynamic Data

More information

LINKED LIST IMPLEMENTATION USING C LANGUAGE: A REVIEW

LINKED LIST IMPLEMENTATION USING C LANGUAGE: A REVIEW LINKED LIST IMPLEMENTATION USING C LANGUAGE: A REVIEW Ekta Nehra Assistant Professor (Extn.), C.R.M jat college, Hisar, Haryana, (India) ABSTRACT This paper describes about linear data structure i.e. linked

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures

More information

Binary Trees. Height 1

Binary 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 information

Cpt S 122 Data Structures. Data Structures

Cpt 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 information

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

COMP26120: Linked List in C (2018/19) Lucas Cordeiro COMP26120: Linked List in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Linked List Lucas Cordeiro (Formal Methods Group) lucas.cordeiro@manchester.ac.uk Office: 2.28 Office hours: 10-11 Tuesday,

More information

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

Data 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 information

That means circular linked list is similar to the single linked list except that the last node points to the first node in the list.

That 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 information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

More information

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

DC104 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 information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

Dynamic Data Structures

Dynamic Data Structures Dynamic Data Structures We have seen that the STL containers vector, deque, list, set and map can grow and shrink dynamically. We now examine how some of these containers can be implemented in C++. To

More information

Data Structures in C. C Programming and Software Tools. N.C. State Department of Computer Science

Data Structures in C. C Programming and Software Tools. N.C. State Department of Computer Science 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 allows for creation

More information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

CS32 Discussion Week 3

CS32 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 information

MODULE V: POINTERS & PREPROCESSORS

MODULE 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 information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/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 information

Stack & Queue on Self-Referencing Structures

Stack & 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 information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

PESIT 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 information

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

COP 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 information

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body; CLASSROOM SESSION Loops in C Loops are used to repeat the execution of statement or blocks There are two types of loops 1.Entry Controlled For and While 2. Exit Controlled Do while FOR Loop FOR Loop has

More information

CS32 - Week 2. Umut Oztok. July 1, Umut Oztok CS32 - Week 2

CS32 - Week 2. Umut Oztok. July 1, Umut Oztok CS32 - Week 2 CS32 - Week 2 Umut Oztok July 1, 2016 Arrays A basic data structure (commonly used). Organize data in a sequential way. Arrays A basic data structure (commonly used). Organize data in a sequential way.

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information

C-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct

C-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct C-types: basic & constructed C basic types: int, char, float, C constructed types: pointer, array, struct Memory Management Code Global variables in file (module) Local static variables in functions Dynamic

More information

CS6202 - 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

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 8: Dynamically Allocated Linked Lists 2017-2018 Fall int x; x = 8; int A[4]; An array is stored as one contiguous block of memory. How can we add a fifth element to the

More information

Linked Lists. Gaddis Ch. 17. CS 2308 :: Spring 2016 Molly O'Neil

Linked Lists. Gaddis Ch. 17. CS 2308 :: Spring 2016 Molly O'Neil Linked Lists Gaddis Ch. 17 CS 2308 :: Spring 2016 Molly O'Neil List ADT A list is an abstract data type representing an ordered sequence of values For example, both MP3 Player assignments have used lists:

More information

Why circular list? check whether a pointer current points to the last node. check for (current->link == first)

Why 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 information

03/31/03 Lab 7. Linked Lists

03/31/03 Lab 7. Linked Lists 03/31/03 Lab 7 Lists are a collection of items in which each item has a specific position. The specification for positioning the items provides some rules of order so this data structure is called an ordered

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

Linked lists. Comp Sci 1575 Data Structures. Definitions. Memory structure. Implementation. Operations. Comparison

Linked lists. Comp Sci 1575 Data Structures. Definitions. Memory structure. Implementation. Operations. Comparison Linked lists Comp Sci 1575 Data Structures Outline 1 2 3 4 5 Linked list Linked lists are of a linear collection of data elements, called nodes, each pointing to the next node Each node is composed of

More information

Self-referential Structures and Linked List. Programming and Data Structure 1

Self-referential Structures and Linked List. Programming and Data Structure 1 Self-referential Structures and Linked List Programming and Data Structure 1 Linked List :: Basic Concepts A list refers to a set of items organized sequentially. An array is an example of a list. The

More information

CA341 - Comparative Programming Languages

CA341 - Comparative Programming Languages CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data

More information

DEPARTMENT 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 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 information

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which

More information

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers School of Electrical and Computer Engineering Cornell University revision: 2017-09-23-11-06 1 Pointer Basics 2 2 Call by Value vs. Call

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. 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 information

CS 171: Introduction to Computer Science II. Linked List. Li Xiong

CS 171: Introduction to Computer Science II. Linked List. Li Xiong CS 171: Introduction to Computer Science II Linked List Li Xiong Roadmap Basic data structure Arrays Abstract data types Stacks Queues Implemented using resizing arrays Linked List Concept and implementations

More information

Programming in C. Lecture 5: Aliasing, Graphs, and Deallocation. Dr Neel Krishnaswami. Michaelmas Term University of Cambridge

Programming in C. Lecture 5: Aliasing, Graphs, and Deallocation. Dr Neel Krishnaswami. Michaelmas Term University of Cambridge Programming in C Lecture 5: Aliasing, Graphs, and Deallocation Dr Neel Krishnaswami University of Cambridge Michaelmas Term 2017-2018 1 / 20 The C API for Dynamic Memory Allocation void *malloc(size_t

More information

Advanced C Programming and Introduction to Data Structures

Advanced C Programming and Introduction to Data Structures FYBCA Semester II (Advanced C Programming and Introduction to Data Structures) Question Bank Multiple Choice Questions Unit-1 1. Which operator is used with a pointer to access the value of the variable

More information

Stack & Queue on Self-Referencing Structures

Stack & 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 information

Heap Arrays. Steven R. Bagley

Heap Arrays. Steven R. Bagley Heap Arrays Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index a[42] = 35; Variables and arrays have a type int, char, double,

More information

Module III. Linear Data Structures and their Linked Storage Representation

Module 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 information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH 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 information

ECE 15B COMPUTER ORGANIZATION

ECE 15B COMPUTER ORGANIZATION ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

APS105. Structures 11/18/2013. Example A struct of stock items at a store: Structures. Lists. Arrays allow a collection of elements

APS105. 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 information

Section I B COMPUTER SCIENCE SOLUTION

Section I B COMPUTER SCIENCE SOLUTION Computer Science Foundation Exam December 17, 2010 Section I B COMPUTER SCIENCE NO books, notes, or calculators may be used, and you must work entirely on your own. SOLUTION Question # Max Pts Category

More information

Linked Lists. Computer Science E-22 Harvard Extension School David G. Sullivan, Ph.D. Representing a Sequence of Data

Linked Lists. Computer Science E-22 Harvard Extension School David G. Sullivan, Ph.D. Representing a Sequence of Data Linked Lists Computer Science E-22 Harvard Extension School David G. Sullivan, Ph.D. Representing a Sequence of Data Sequence an ordered collection of items (position matters) we will look at several types:

More information

Elementary Data Structures: Part 1: Arrays, Lists. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Elementary Data Structures: Part 1: Arrays, Lists. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Elementary Data Structures: Part 1: Arrays, Lists CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1 Basic Types Types like integers, real numbers, characters.

More information

Fundamentals of Data Structure

Fundamentals of Data Structure Fundamentals of Data Structure Set-1 1. Which if the following is/are the levels of implementation of data structure A) Abstract level B) Application level C) Implementation level D) All of the above 2.

More information

School of Electrical Engineering & Computer Science Oregon State University. CS Recitation 3 Spring 2012

School of Electrical Engineering & Computer Science Oregon State University. CS Recitation 3 Spring 2012 School of Electrical Engineering & Computer Science Oregon State University CS 261 - Recitation 3 Spring 2012 Bitwise Operators AND (&), OR ( ), XOR(^), Complement (~) In all our examples sizeof(int) =

More information

Computer Systems and Networks

Computer Systems and Networks University of the Pacific LECTURE 5: C PROGRAMMING Computer Systems and Networks Dr. Pallipuram (vpallipuramkrishnamani@pacific.edu) Today s Class o Pointer basics o Pointers and mul;- dimensional arrays

More information

Outline. 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 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 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 (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 information

CSC 1052 Algorithms & Data Structures II: Linked Queues

CSC 1052 Algorithms & Data Structures II: Linked Queues CSC 1052 Algorithms & Data Structures II: Linked Queues Professor Henry Carter Spring 2018 Recap A queue simulates a waiting line, where objects are removed in the same order they are added The primary

More information

Structures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; };

Structures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; }; Structures EECS 2031 25 September 2017 1 Basics of Structures (6.1) struct point { int x; int y; keyword struct introduces a structure declaration. point: structure tag x, y: members The same member names

More information

ECE 2035 Programming HW/SW Systems Spring problems, 5 pages Exam Three 8 April Your Name (please print clearly)

ECE 2035 Programming HW/SW Systems Spring problems, 5 pages Exam Three 8 April Your Name (please print clearly) Your Name (please print clearly) This exam will be conducted according to the Georgia Tech Honor Code. I pledge to neither give nor receive unauthorized assistance on this exam and to abide by all provisions

More information

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information