TA: Nouf Al-Harbi nouf200@hotmail.com Data Structures LAB 2 TA: Nouf Al-Harbi nouf200@hotmail.com.

Slides:



Advertisements
Similar presentations
Sorted Lists CS Data Structures Sections 4.1, 4.2 & 4.3.
Advertisements

Alan YorinksLecture 7 1 • Tonight we will look at:: • List ADT • Unsorted List • Sequential Search • Selection Sort • Sorted List • Binary Search.
ADTs unsorted List and Sorted List
Computer Science and Software Engineering University of Wisconsin - Platteville 5. LinkedList Yan Shi CS/SE 2630 Lecture Notes.
Chapter 3 ADT Unsorted List. List Definitions Linear relationship Each element except the first has a unique predecessor, and Each element except the.
C++ Plus Data Structures ADTs Unsorted List and Sorted List
1 Jake’s Pizza Shop Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len.
Unsorted Lists CS 308 – Data Structures. What is a list? A list is a homogeneous collection of elements. Linear relationship between elements: (1) Each.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles.
Chapter 4 ADT Sorted List.
Sorted Lists CS Data Structures. Sorted List Specification (partial) InsertItem (ItemType item) Function: Adds item to list Preconditions: (1) List.
Implementing an Unsorted List as a Linked Structure CS 308 – Data Structures.
1 Nell Dale Chapter 3 ADTs Unsorted List and Sorted List Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Typical operations on data –Add data.
1 Chapter 6 Object-Oriented Software Development.
5 Linked Structures. 2 Definition of Stack Logical (or ADT) level: A stack is an ordered group of homogeneous items (elements), in which the removal and.
1 Chapter 6 Lists Plus. ADT Sorted List Operations Transformers n MakeEmpty n InsertItem n DeleteItem Observers n IsFull n LengthIs n RetrieveItem Iterators.
1 Nell Dale Chapter 6 Lists Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Doubly Linked Lists CS 308 – Data Structures. Node data info: the user's data next, back: the address of the next and previous node in the list.back.next.info.
Dynamic Structures & Arrays.
1 Fall Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List.
Implementing a Sorted List as a Linked Structure CS 308 – Data Structures.
Chapter 4 ADT Sorted List.
1 Nell Dale Chapter 6 Lists Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Chapter 3 ADT Unsorted List. Lecture 7 List Definitions Linear relationship Each element except the first has a unique predecessor, and Each element.
Linked List. List Definitions Linear relationship Each element except the first has a unique predecessor, and each element except the last has a unique.
Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List operations.
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.
3 ADT Unsorted List. List Definitions Linear relationship Each element except the first has a unique predecessor, and each element except the last has.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
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.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
1 Nell Dale Chapter 8 Binary Search Trees Modified from the slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data.
1 C++ Plus Data Structures Nell Dale Chapter 5 Linked Structures Modified from the slides by Sylvia Sorkin, Community College of Baltimore County - Essex.
Chapter 4 ADT Sorted List. Sorted Type Class Interface Diagram SortedType class IsFull GetLength ResetList DeleteItem PutItem MakeEmpty GetItem Private.
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.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
CS 302 – Data Structures Sections 3.1, 3.2, 3.4 & 3.5
1 Nell Dale Lecture 3 ADTs Unsorted List and Sorted List Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Modified by Reneta.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
CSI 1340 Introduction to Computer Science II Chapter 3 ADTs Unsorted List and Sorted List.
1 Chapter 4 ADT Sorted List. 2 Sorted Type Class Interface Diagram SortedType class IsFull LengthIs ResetList DeleteItem InsertItem MakeEmpty RetrieveItem.
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
1 Nell Dale Chapter 8 Binary Search Trees Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
CSCE 210 Data Structures and Algorithms
Chapter 13 Applied Arrays: Lists and Strings
C++ Plus Data Structures ADTs Unsorted List and Sorted List
TA: Nouf Al-Harbi Data Structures LAB 3 TA: Nouf Al-Harbi
Data Abstraction: The Walls
C++ Plus Data Structures
Lists The List ADT.
Stack and Queue APURBO DATTA.
Chapter 16-2 Linked Structures
C++ Plus Data Structures
Unsorted Lists CS3240, L. Grewe.
Data Abstraction: The Walls
Chapter 16 Linked Structures
Chapter 9 Priority Queues and Sets
CSI 1340 Introduction to Computer Science II
Chapter 13 Applied Arrays: Lists and Strings
Yan Shi CS/SE 2630 Lecture Notes
Data Structures and Algorithms Memory allocation and Dynamic Array
Lists CMSC 202, Version 4/02.
Data Abstraction: The Walls
Lists CMSC 202, Version 4/02.
Presentation transcript:

TA: Nouf Al-Harbi nouf200@hotmail.com Data Structures LAB 2 TA: Nouf Al-Harbi nouf200@hotmail.com

Data structures lab 2 Unsorted List

objectives By the end of this lab you will be able to : Implement Unsorted List Class with all its operations Unsorted List

List A list is a homogeneous collection of elements with a linear relationship between elements. each list element (except the first) has a unique predecessor each element (except the last) has a unique successor. 4 3 2 1 Nada Reema Amal Lama Sara predecessor successor Unsorted List

Unsorted & Sorted List Unsorted List Sorted List Elements are placed into the list in no particular order. List elements are in an order that is sorted in some way May be numerically or alphabetically , … etc. Unsorted List

Unsorted List Example .. Implement Unsorted List of 10 integer elements Unsorted List

UnsortedType class (data & methods members) 3 data members Info Array of 10 elements Actual data of list Length Determines the length of list Ranges between 0 (No elements and 10 (max number of elements) CurrentPos As an index Ranges between -1 (prior to 1st element )and the length - 1(points to the last element) Private data: length info [ 0 ] [ 1 ] [ 2 ] [ 9 ] currentPos

UnsortedType class (data & methods members) Constructor MakeEmpty Private data: length info [ 0 ] [ 1 ] [ 2 ] [ 9 ] currentPos InsertItem Transformers change state DeleteItem IsFull Observers Observe state LengthIs RetrieveItem ResetList Iterators Process All GetNextItem

Implementing Unsorted Class the class declaration is placed in one file (header file)  Unsorted.h the implementation of all the methods is put in another fileUnsorted.cpp the Main function is put in another file  UnsortedList.cpp Foe each Unsorted.cpp & UnsortedList we should inclusde Unsorted.h file #include “Unsorted. h” Unsorted List

Implementing Unsorted Class 1- class declaration Unsorted.h Unsorted List

unsorted.h // SPECIFICATION FILE ( unsorted.h ) class UnsortedType // declares a class data type { public: // 8 public member functions UnsortedType(); void MakeEmpty ( ) ; bool IsFull ( ) const ; int LengthIs ( ) const ; // returns length of list bool RetrieveItem ( int item ) ; void InsertItem ( int item ) ; void DeleteItem ( int item ) ; void ResetList ( ); int GetNextItem ( ) ; private: // 3 private data members int info[10] ; int currentPos ; int length; } ; Unsorted List

Implementing Unsorted Class 2- implementation of all the methods Unsorted.cpp Unsorted List

UnsortedType Counstructor UnsortedType::UnsortedType() { length = 0; }

MakeEmpty Method void UnsortedType::MakeEmpty ( ) { length = 0 ; }

Inside constant functions we can’t change data values IsFull Method IsFull Full  True Not full  false Inside constant functions we can’t change data values bool UnsortedType::IsFull ( ) const { return (length == 10) ; }

LengthIs Method LengthIs int UnsortedType::LengthIs ( ) const { Length of the list int UnsortedType::LengthIs ( ) const { return length ; }

The item that will be inserted InsertItem Method InsertItem The item that will be inserted void UnsortedType::InsertItem ( int item ) { info[length] = item ; length++ ; }

The item that will be searched for RetrieveItem Method RetrieveItem The item that will be searched for Found  true Not found  false bool UnsortedType::RetrieveItem (int item) { int location = 0 ; //index bool found = false ; for(location=0;location<length;location++) if(item==info[location]) found=true; } return found };

The item that will be deleted DeleteItem Method DeleteItem The item that will be deleted void UnsortedType::DeleteItem ( int item ) { int location = 0 ; for(location=0;location<length;location++) if(item==info[location]) info [location] = info [length - 1 ] ; length-- ; }

ResetList Method void UnsortedType::ResetList ( ) { currentPos = -1 ; }

The item that follows the current item GetNextItem Method GetNextItem The item that follows the current item int UnsortedType::GetNextItem ( ) { int item; currentPos++; item = info[currentPos]; return item ; }

Implementing Unsorted Class 3- Main function UnsortedList.cpp Unsorted List

In Main function .. Insert some elements into the list (taken form user) Search for element (taken from user) Ask whether the List is full or not Display the elements that are in the list. Delete an element from the list (taken form user) Display the elements that are in the list (After Deletion) Unsorted List