TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Why not just use Arrays? Java ArrayLists.
Linear Lists – Array Representation
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
Linked Lists Linear collections.
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
F28PL1 Programming Languages Lecture 14: Standard ML 4.
Queues CSE, POSTECH 2 2 Queues Like a stack, special kind of linear list One end is called front Other end is called rear Additions (insertions or enqueue)
Queue Chapter 9 Stacks Last in first out (LIFO)Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top.
List Representation - Chain Fall 2010 CSE, POSTECH.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
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.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
Abstract Data Types data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Typical operations on data –Add data.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
Data Structures data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
Stacks CSE, POSTECH. 2 2 Stacks Linear list One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Homework –Continue Reading K&R Chapter 2 –We’ll go over HW2 –HW3 is posted Questions?
Iterators & Chain Variants. Iterators  An iterator permits you to examine the elements of a data structure one at a time.  C++ iterators Forward iterator.
1 Chapter 3 Data Representation Part 1. 2 Goals Introduce the different ways in which data may be represented Concepts –Abstract data types –Formula-based,
Containers Overview and Class Vector
Linear List Linked Representation. Linked Representation list elements are stored, in memory, in an arbitrary order explicit information (called a link)
Data Collections: Dictionaries CSC 161: The Art of Programming Prof. Henry Kautz 11/4/2009.
Lecture DS & Algorithms:09 Abstract Data Types. Lecture DS & Algorithms:09 2 Abstract Data Types Data Type: A data type is a collection of values and.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
SNU IDB Lab. Ch5. Linear Lists – Array Representation © copyright 2006 SNU IDB Lab.
Stacks Chapter 8. Objectives In this chapter, you will: Learn about stacks Examine various stack operations Learn how to implement a stack as an array.
Applications of Stacks and Queues Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Linear List Array representation Data structures A data structure is a particular way of storing and manipulating data in a computer so that it can be.
Abstract Data Types and a review of C++ programming concepts CS 400/600 – Data Structures.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
ITERATORS. Iterator An iterator in C++ is a concept that refines the iterator design pattern into a specific set of behaviors that work well with the.
1 Homework –Continue Reading K&R Chapter 2 –We’ll go over HW2 at end of class today –Continue working on HW3 Questions?
The Class Chain. next (datatype ChainNode) element (datatype Object) Use ChainNode abcde null firstNode size = number of elements.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Data Structure Specification  Language independent  Abstract Data Type  C++  Abstract Class.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
Linear (or Ordered) Lists instances are of the form (e 0, e 1, e 2, …, e n-1 ) where e i denotes a list element n >= 0 is finite list size is n.
The Class arrayList General purpose implementation of linear lists. Unknown number of lists.
Reminder: Course Policy
-TAs and office hours announced
The Class ArrayLinearList
Data Abstraction: The Walls
Abstract Data Types data object set or collection of instances
List Representation - Array
The Class chain.
Stacks template<class T> class stack { public:
Object Oriented Programming COP3330 / CGS5409
The Class arrayList General purpose implementation of linear lists.
Programming in Java Lecture 11: ArrayList
-TAs and office hours announced
Stacks template<class T> class stack { public:
Queues Linear list. One end is called front. Other end is called rear.
Stacks template<class T> class stack { public:
QUIZ.
The Class chain.
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
The Class chain.
01 DRAW YOUR TIMELINE HERE JAN. MAR. JAN. MAR. FEB. APR. FEB. APR.
Stacks template<class T> class stack { public:
Lists - I The List ADT.
Lists - I The List ADT.
Arrays and ArrayLists.
The List Container and Iterators
Data Structures & Programming
Presentation transcript:

TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:

Data Structures data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}

Data Object instances may or may not be related myDataObject = {apple, chair, 2, 5.2, red, green, Jack}

Data Structure Data object + relationships that exist among instances and elements that comprise an instance Among instances of integer 369 < = 284

Data Structure Among elements that comprise an instance is more significant than 6 3 is immediately to the left of 6 9 is immediately to the right of 6

The relationships are usually specified by specifying operations on one or more instances. add, subtract, predecessor, multiply Data Structure

Linear (or Ordered) Lists instances are of the form (e 0, e 1, e 2, …, e n-1 ) where e i denotes a list element n >= 0 is finite list size is n

Linear Lists L = (e 0, e 1, e 2, e 3, …, e n-1 ) relationships e 0 is the zero’th (or front) element e n-1 is the last element e i immediately precedes e i+1

Linear List Examples/Instances Students in COP3530 = (Jack, Jill, Abe, Henry, Mary, …, Judy) Exams in COP3530 = (exam1, exam2, exam3) Days of Week = (S, M, T, W, Th, F, Sa) Months = (Jan, Feb, Mar, Apr, …, Nov, Dec)

Linear List Operations—size() determine list size L = (a,b,c,d,e) size = 5

Linear List Operations—get(theIndex) get element with given index L = (a,b,c,d,e) get(0) = a get(2) = c get(4) = e get(-1) = error get(9) = error

Linear List Operations— indexOf(theElement) determine the index of an element L = (a,b,d,b,a) indexOf(d) = 2 indexOf(a) = 0 indexOf(z) = -1

Linear List Operations— erase(theIndex) Remove/delete element with given index L = (a,b,c,d,e,f,g) erase(2) removes c and L becomes (a,b,d,e,f,g) index of d,e,f, and g decrease by 1

Linear List Operations— erase(theIndex) Remove/delete element with given index L = (a,b,c,d,e,f,g) remove(-1) => error remove(20) => error

Linear List Operations— insert(theIndex, theElement) add an element so that the new element has a specified index L = (a,b,c,d,e,f,g) insert(0,h) => L = (h,a,b,c,d,e,f,g) index of a,b,c,d,e,f, and g increase by 1

Linear List Operations— insert(theIndex, theElement) L = (a,b,c,d,e,f,g) insert(2,h) => L = (a,b,h,c,d,e,f,g) index of c,d,e,f, and g increase by 1 add(10,h) => error add(-6,h) => error

Data Structure Specification  Language independent  Abstract Data Type  C++  Abstract Class

Linear List Abstract Data Type AbstractDataType LinearList { instances ordered finite collections of zero or more elements operations empty(): return true iff the list is empty, false otherwise size(): return the list size (i.e., number of elements in the list) get(index): return the indexth element of the list indexO f(x): return the index of the first occurrence of x in the list, return -1 if x is not in the list erase(index): remove the indexth element, elements with higher index have their index reduced by 1 insert(theIndex, x): insert x as the indexth element, elements with theIndex >= index have their index increased by 1 output(): output the list elements from left to right }

Linear List As An Abstract Class An abstract class may include constants, variables, abstract methods, and nonabstract methods.

Linear List As C++ Abstract Class template class linearList { public: virtual ~linearList() {}; virtual bool empty() const = 0; virtual int size() const = 0; virtual T& get(int theIndex) const = 0; virtual int indexOf(const T& theElement)const = 0; virtual void erase(int theIndex) = 0; virtual void insert(int theIndex, const T& theElement) = 0; virtual void output(ostream& out) const = 0; };

Extending A C++ Class template class arrayList : public linearList { // code for all abstract methods of linearList must come here }

To-do Git: – echnical/git/ echnical/git/ – s C++: – /tutorial/templates/ /tutorial/templates/