ICOM 4015 Advanced Programming

Slides:



Advertisements
Similar presentations
Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Advertisements

Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
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.
FALL 2001ICOM Lecture 21 ICOM 4015 Advanced Programming Lecture 2 Procedural Abstraction Reading: LNN Chapter 4, 14 Prof. Bienvenido Velez.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Pointers OVERVIEW.
1 Writing a Good Program 8. Elementary Data Structure.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
CSE 332: C++ template examples Today: Using Class and Function Templates Two examples –Function template for printing different types –Class template for.
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
CSC 143 P 1 CSC 143 Recursion [Chapter 5]. CSC 143 P 2 Recursion  A recursive definition is one which is defined in terms of itself  Example:  Compound.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
CISC220 Spring 2010 James Atlas Lecture 04: Pointers, Functions, Memory Management, ADTs, Classes, Hardware, Software, Graphics, Networking, AI, Databases,
1 Data Structures and Algorithms Queue. 2 The Queue ADT Introduction to the Queue data structure Designing a Queue class using dynamic arrays Linked Queues.
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
CSCE 210 Data Structures and Algorithms
CSCE 210 Data Structures and Algorithms
Popping Items Off a Stack Using a Function Lesson xx
CS505 Data Structures and Algorithms
Linked List :: Basic Concepts
Lectures linked lists Chapter 6 of textbook
UNIT – I Linked Lists.
Lists CS 3358.
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Traversing a Linked List
Linked lists.
Stack and Queue APURBO DATTA.
Chapter 4 Linked Lists
Linked List Yumei Huo Department of Computer Science
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
CSC 253 Lecture 8.
Stack ADT & Modularity 2 implementations of the Stack abstract data type: Array Linked List Program design: modularity, abstraction and information hiding.
Chapter 16-2 Linked Structures
CSC 253 Lecture 8.
Linked List Lesson xx   In this presentation, we introduce you to the basic elements of a linked list.
Popping Items Off a Stack Lesson xx
Pointers, Dynamic Data, and Reference Types
Dynamic Memory A whole heap of fun….
Doubly Linked List Implementation
Linked Lists Chapter 4.
Dynamic Memory A whole heap of fun….
Chapter 16 Linked Structures
TUTORIAL 11 CS 137 F18 November 27th.
Dynamic Memory.
Lists.
CS150 Introduction to Computer Science 1
CS410 – Software Engineering Lecture #5: C++ Basics III
Classes with dynamic members
Lists CMSC 202, Version 4/02.
ICOM 4015 Advanced Programming
Lists CMSC 202, Version 4/02.
ICOM 4015 Advanced Programming
Linked lists.
ICOM 4015 Advanced Programming
Abstract Data Types Stacks CSCI 240
Lecture 4 – Data collection List ADT
Data Structures & Programming
Presentation transcript:

ICOM 4015 Advanced Programming Lecture 7 Dynamic Memory II Abstract Data Types Reading: LNN Chapter Prof. Bienvenido Vélez 5/27/2019 ICOM 4015

Dynamic Memory II Outline Abstract data types (ADT) List Abstract Data Type Linked list implementation of List ADT 5/27/2019 ICOM 4015

Problem Need to Store set of Dynamic Objects Solution 1: Dynamic Arrays PROGRAM code Array Pointer object Global static variables p STACK activation records HEAP Dynamic objects dynamic array 5/27/2019 ICOM 4015

Problem Need to Store set of Dynamic Objects Solution 2: Linked Structure PROGRAM code Pointer object Global static variables p STACK activation records HEAP Dynamic objects dynamic array 5/27/2019 ICOM 4015

A List Abstract Data Type (ADT) // lists.h // Global declarations for linked lists module // List data structures typedef int DatumType; struct Node { DatumType datum; Node* next; }; struct List { Node* first; Node* current; int length; // Operations on linked lists // List initialization void listInit (List& l); // List modification List& listAppend (List& l, DatumType d); List& listPrepend(List& l, DatumType d); List& listInsert (List& l, DatumType d); // List interation void listStart (List& l); void listNext (List& l); DatumType listCurrent(const List l); bool listEOL (const List l); // List printing void listDump (const List l); 5/27/2019 ICOM 4015

Linked lists implementation of List ADT (Part I) // lists.cc // Implementes singly linked lists ADT extern "C" { #include <stdlib.h> } #include <iostream> #include "lists.h" Node* NullNode = (Node *)NULL; // Operations on linked lists // List initialization void listInit(List& l) { l.first = NullNode; l.current = NullNode; l.length = 0; // List modification List& listAppend(List& l, DatumType d) Node* temp = new Node; temp->next = NullNode; temp->datum = d; if (l.first == NullNode) { l.first = temp; else { Node* n = l.first; while(n->next != NullNode) { n = n->next; n->next = temp; l.length++; return l; 5/27/2019 ICOM 4015

Linked lists implementation of List ADT (Part II) List& listPrepend(List& l, DatumType d) { Node* temp = new Node; temp->datum = d; temp->next = l.first; l.first = temp; } void listStart(List& l) l.current = l.first; void listNext(List& l) if (l.current != NullNode) { l.current = l.current->next; List& listInsert(List& l, DatumType d) Node* n = l.current; temp->next = l.current->next; l.current->next = temp; DatumType listCurrent(const List l) return l.current->datum; bool listEOL(const List l) return (l.current == NullNode); 5/27/2019 ICOM 4015

Using the List ADT IMPORTANT #include <iostream> #include "lists.h" int main() { List l; listInit(l); for(int i = 1; i < 10; i++) { listPrepend(l,i); } cout << "Original list" << endl; listDump(l); // Demonstrate iteration without exposing pointers for (listStart(l); !listEOL(l); listNext(l)) { DatumType curr = listCurrent(l); cout << "Next datum: " << curr << endl; listStart(l); listNext(l); listInsert(l,100); cout << "List with 100 inserted" << endl; IMPORTANT The fact that the list is implemented using pointers remains hidden from users of the module. The implementation ABSTRACTS OUT irrelevant detail 5/27/2019 ICOM 4015

List ADT Output [bvelez@amadeus] ~/icom4015/lec15 >>g++ lists.cc main.cc -o lists [bvelez@amadeus] ~/icom4015/lec15 >>lists Original list 9 8 7 6 5 4 3 2 1 Next datum: 9 Next datum: 8 Next datum: 7 Next datum: 6 Next datum: 5 Next datum: 4 Next datum: 3 Next datum: 2 Next datum: 1 List with 100 inserted 100 [bvelez@amadeus] ~/icom4015/lec15 >> 5/27/2019 ICOM 4015

Abstract Data Types (ADT) Summary Consists of the definition of a type of object and a set of operations that can be performed on object of the type An ADT describes a type of object together with the set of operations defined on the object An ADT hides irrelevant implementation details An ADT shields its users from dependencies on hidden details 5/27/2019 ICOM 4015