Abstract Data Types and a review of C++ programming concepts CS 400/600 – Data Structures.

Slides:



Advertisements
Similar presentations
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Advertisements

COMP171 Fall 2005 Lists.
Linear Lists – Array Representation
Lists A list is a finite, ordered sequence of data items. Important concept: List elements have a position. Notation: What operations should we implement?
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Data Structures ADT List
DATA STRUCTURES USING C++ Chapter 5
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.
1 Linked List Position (1). 2 Linked List Position (2)
Queue ADTs Queue concepts. Queue applications. A queue ADT: requirements, contract. Implementations of queues: using arrays, linked lists.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
CS 340Chapter 3: Lists, Stacks, and Queues1 Abstract Data Types An ADT is a set of operations upon a set of data. Implementation details are not specified.
Abstract Data Type Example l One more example of ADT: l integer linked list using class l A class with dynamic objects: l Copy constructor l Destructor.
Linked Lists. COMP104 Lecture 33 / Slide 2 Linked Lists: Basic Idea * Data may be stored consecutively in a linked list. * Each element of the linked.
C++ is Fun – Part 14 at Turbine/Warner Bros.! Russell Hanson.
E.G.M. Petrakislists, stacks, queues1 Lists List: finite sequence of data elements –Ordered: each element has a position in list –All elements has the.
Chapter 17 Linked List.
Introduction to Ruby CS 480/680 – Comparative Languages.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
March 6, 2014CS410 – Software Engineering Lecture #10: C++ Basics IV 1 Structure Pointer Operator For accessing members in structures and classes we have.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
3 ADT Unsorted List. List Definitions Linear relationship Each element except the first has a unique predecessor, and each element except the last has.
1 Chapter 7 The Linked List as a Data Structure. 2 The List ADT A list is a list of elements. The list of elements consist of the data acted upon by list.
Review of Lists, Stacks, and Queues CS 400/600 – Data Structures.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
1 Data Structures CSCI 132, Spring 2014 Lecture 20 Linked Lists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
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.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
CHAPTER 17 LINKED LISTS. In this chapter, you will:  Learn about linked lists  Become aware of the basic properties of linked lists  Explore the insertion.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
UNCA CSCI September, 2001 These notes were prepared by the text’s author Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright.
What is a List? A list is a homogeneous collection of elements, with a linear relationship between elements. Each list element (except the first) has a.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
1 CSC 211 Data Structures Lecture 11 Dr. Iftikhar Azim Niaz 1.
Linked List.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
CSCE 210 Data Structures and Algorithms
CS505 Data Structures and Algorithms
Chapter 4 The easy stuff.
Doubly Linked List Review - We are writing this code
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
classes and objects review
Priority Queue.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Queues.
Data Structures ADT List
Data Structures ADT List
Data structures in C++.
Basics of Algorithm Analysis
Lists List: finite sequence of data elements
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
CSCI 333 Data Structures Chapter 4 13 and 16 September 2002.
ADT list.
Queues CSC212.
Data Structures ADT List
CS150 Introduction to Computer Science 1
Lists CMSC 202, Version 4/02.
Lists CMSC 202, Version 4/02.
Abstract Data Types Stacks CSCI 240
Data Structures & Programming
Data Structures & Programming
Presentation transcript:

Abstract Data Types and a review of C++ programming concepts CS 400/600 – Data Structures

ADTs and SimpleList2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely in terms of a set of values and a set of operations on that data type. Each ADT operation is defined by its inputs and outputs. Encapsulation: Hide implementation details.

ADTs and SimpleList3 Data Structure  A data structure is the physical implementation of an ADT. Each operation associated with the ADT is implemented by one or more subroutines in the implementation.  Data structure usually refers to an organization for data in main memory.

ADTs and SimpleList4 SimpleList  Values: integers (to start with)  Operations: bool Slist.insertfront(int i) bool Slist.insertend(int i) bool Slist.getfirst(int &i) bool Slist.getlast(int &i) void Slist.clear()

ADTs and SimpleList5 SimpleList Implementation  Implement as an unsorted single-linked list class Lnode { public: int value; Lnode *next; Lnode(int newvalue = 0) {value = newvalue; next = NULL;} }

ADTs and SimpleList6 SimpleList Implementation class Slist { private: Lnode* head; public: Slist() {head = NULL;} ~Slist(){clear();} bool insertfront(int i); bool insertend(int i); bool getfirst(int &val); bool getlast(int &val); void clear(); }

ADTs and SimpleList7 SimpleList Implementation bool Slist::insertfront(int i) { Lnode* newnode = new Lnode(i); newnode->next = head; head = newnode; } bool Slist::insertend(int i) { Lnode* newnode = new Lnode(i); Lnode* last = head; if (head == NULL) { head = newnode; return; } while (last->next != NULL) { last = last->next; } last->next = newnode; }

ADTs and SimpleList8 SimpleList Implementation bool Slist::getfirst(int &val) { Lnode* oldhead = head; if (head == NULL) {return false;} val = head->value; head = head->next; delete(oldhead); return true; } void Slist::clear() { Lnode* oldnode; while (head != NULL) { oldnode = head; head = head->next; delete(oldnode); }

ADTs and SimpleList9 Using the SimpleList Slist mylist; intval; mylist.insertfront(7); mylist.insertfront(3); mylist.insertend(12); cout << “Here’s the list: “; while (mylist.getfirst(val)) { cout << val << “, “; } cout << endl;

ADTs and SimpleList10 Extending the class  What if we want to be able to store a list of any type of data type/class?  We can make this into a template to allow the class to be filled in later. template class Lnode { public: Elem data; Lnode *next; Lnode( & newvalue) {data = newvalue; next = NULL;} }

ADTs and SimpleList11 Using the template Lnode node(3.14); Class Lnode { public: double data; Lnode *next; Lnode (double& newvalue) {data = newvalue; next = NULL;} }

ADTs and SimpleList12 Defining an ADT  C++’s abstract classes are a good way to define an ADT: // List abstract class template class List { public: // Reinitialize the list. The client is responsible for // reclaiming the storage used by the list elements. virtual void clear() = 0; // Insert an element at the front of the right partition. // Return true if successful, false if the list is full. virtual bool insert(const Elem&) = 0; // Append an element at the end of the right partition. // Return true if successful, false if the list is full. virtual bool append(const Elem&) = 0; // Remove the first element of right partition. Return // true if successful, false if right partition is empty. // The element removed is returned in the parameter. virtual bool remove(Elem&) = 0; // Place fence at list start, making left partition empty virtual void setStart() = 0; …

ADTs and SimpleList13 Defining an ADT // List abstract class, continued… // Place fence at list end, making right partition empty virtual void setEnd() = 0; // Move fence one step left; no change if already at start virtual void prev() = 0; // Move fence one step right; no change if already at end virtual void next() = 0; // Return length of left partition virtual int leftLength() const = 0; // Return length of right partition virtual int rightLength() const = 0; // If pos or more elements are in the list, set the size // of left partition to pos and return true. Otherwise, // do nothing and return false. virtual bool setPos(int pos) = 0; // Return in first parameter the first element of the // right partition. Return true if successful, false // if the right partition is empty. virtual bool getValue(Elem&) const = 0; // Print the contents of the list virtual void print() const = 0; };