Advanced Data Structures Stack –a stack is dynamic data items in a linear order, such that the item first "pushed" in is the last item "popped" out. Think.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
CSCI2100B Linked List Jeffrey
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 7 : September 8.
C Programming : Elementary Data Structures 2009/04/22 Jaemin
Chapter 13 Pointers and Linked Lists. Nodes and Linked Lists Linked list: A sequence of nodes in which each node is linked or connected to the node preceding.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Digital Electronics Data Structures LISP
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
Grade 12 Computer Studies HG
UNIT-2. Singly Linked List Doubly Linked List Circular Linked List Representing Stack with Linked List. Representing Queue with Linked List.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
Pointers OVERVIEW.
Self-Referential Classes A Self-referential class is a class that contains a reference to an object that has the same class type. –A self-referential class.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Programming Practice 3 - Dynamic Data Structure
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
12/23/2015Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 9 An Introduction.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Fall 2006 METU EEEEE 441 S. Ece (GURAN) SCH MIDT EE 441 Data Structures Lecture 6 Stacks and Queues.
CNG 140 C Programming (Lecture set 12) Spring Chapter 13 Dynamic Data Structures.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Advanced Pointers and Structures Pointers in structures Memory allocation Linked Lists –Stacks and queues Trees –Binary tree example.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
(1-3) Basics of a Linked List I Instructor - Andrew S. O’Fallon CptS 122 (June 9, 2016) Washington State University.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
STACKS & QUEUES for CLASS XII ( C++).
Pointers and Linked Lists
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
5.13 Recursion Recursive functions Functions that call themselves
Data Structure #1: The Array
12 C Data Structures.
12 C Data Structures.
Chapter 15 Lists Objectives
Data Structures and Algorithms
Stack and Queue APURBO DATTA.
Chapter 20: Binary Trees.
Pointers and Linked Lists
LINKED LISTS.
Chapter 21: Binary Trees.
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Stack and Queues Stack implementation using Array
Stack and Queues Stack implementation using Array
Review & Lab assignments
Data Structures and Algorithms
Stacks and Queues.
Presentation transcript:

Advanced Data Structures Stack –a stack is dynamic data items in a linear order, such that the item first "pushed" in is the last item "popped" out. Think of stack as a stack of books, you are only allowed to put a book on top of the stack or take a book from top of the stack Stack empty Item 1 pushed on stack Item 2 pushed on stack Item 2 popped off stack

Advanced Data Structures Queue –a queue is dynamic data items in a linear order, such that the item first goes in is the first item goes out. Think of a queue as a queue of people. Item goes in from one end and comes out from the other end.

Advanced Data Structures Tree –a tree is dynamic data items in an order similar to the hierarchical structure of tree in nature. Each "node" can have a number of "children". Each child can have a number of children and so on.

Structure The stack, queue, or tree data structure can be implemented with structure and pointer to structure. The basic element or node is of type struct node { int num;...; struct node *pt; }; Any number of information fields. One or more pointers to the same structure (self- referential).

Linked Lists A (linked) list of names of elephants can be represented with the structure: struct elephant { char name[10]; struct elephant *next; }; start = &e1; e1.next = &e2; e2.next = &e3; e3.next = NULL; start "Edna" "Elmer""Eloise" e1e2e3 name next name next name next

Why Use Linked List? The linked list has advantage over fixed-size array –The list can be extended by inserting a node anywhere in the list. –The list can be shortened by deleting a node. –The list can be used to implement a stack or queue.

Print a Linked List #include typedef struct elephant { char name[10]; struct elephant *next; } ELEPHANT; void print_elephants(const ELEPHANT* ptr); main() { ELEPHANT e1, e2, e3, *start; strcpy(e1.name, "Edna"); strcpy(e2.name, "Elmer"); strcpy(e3.name, "Eloise"); start = &e1; e1.next = &e2; e2.next = &e3; e3.next = NULL; print_elephants(start); } void print_elephants(const ELEPHANT* ptr) { int count = 1; printf("\n"); while(ptr != NULL) { printf("\nElephant numer %d is %s.", count++, ptr -> name); ptr = ptr -> next; }

Add a Node in front of the List  start e1 e2 new new = malloc(sizeof(ELEPHANT)); new->next = start; strcpy(new->name, "Tha"); start = new; "Tha" "Edna""Elmer"

Delete a Node old = ptr -> next; ptr->next = old->next; free(old); ptr old

Binary Tree struct tree { int nums; struct tree *left, *right; }

Assertions An assertion is a condition that must always be true at some particular point of the program's execution. Assertions, which are embedded in the code, are checked for correctness when the program is running. When an assertion fails, the program terminates and issue error messages. In C, we can put in assertion by #include... assert(condition); where the condition is any single expression, nonzero for true, 0 for false. Example: assert(a<b);

C Language Features not Discussed Some of the preprocessing directives like #pragma, and stringization #x. Pointers to functions. Functions with variable number of arguments. Some less commonly used functions in standard libraries such as,,,... Exception-handling and jumps.