1 / 23

Data Structures LAB 2

Data Structures LAB 2. TA: Nouf Al-Harbi nouf200@hotmail.com . Data structures lab 2. Unsorted List. objectives. By t he end of this lab you will be able to : Implement Unsorted List Class with all its operations. List. A list is a homogeneous collection of elements

zanta
Download Presentation

Data Structures LAB 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data StructuresLAB 2 TA: Nouf Al-Harbi nouf200@hotmail.com

  2. Data structures lab 2 Unsorted List

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

  4. 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. predecessor successor Unsorted List

  5. 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

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

  7. Private data: length info [ 0 ] [ 1 ] [ 2 ] [ 9 ] currentPos 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)

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

  9. 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 inclusdeUnsorted.h file • #include “Unsorted. h” Unsorted List

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

  11. unsorted.h Unsorted List

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

  13. UnsortedType Counstructor

  14. MakeEmpty Method

  15. IsFull Method • Full  True • Not full  false Inside constant functions we can’t change data values

  16. LengthIs Method • Length of the list

  17. InsertItem Method • The item that will be inserted

  18. RetrieveItem Method • The item that will be searched for • Found  true • Not found  false

  19. DeleteItem Method • The item that will be deleted

  20. ResetList Method

  21. GetNextItem Method The item that follows the current item

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

  23. 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

More Related