data structures
DESCRIPTION
Data Structures. Summary of lectures (1 to 11) Azhar Maqsood NUST Institute of Information Technology (NIIT). Features of c++ you need to know. Variables Parameter Passing Pointers Classes and Objects Inheritance Others. An Array!. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/1.jpg)
Data Structures
Summary of lectures (1 to 11)
Azhar MaqsoodNUST Institute of Information Technology (NIIT)
![Page 2: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/2.jpg)
Features of c++ you need to know
• Variables• Parameter Passing• Pointers• Classes and Objects• Inheritance• Others
![Page 3: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/3.jpg)
An Array!
The simplest form of an Array is a one dimensional array that may be defined as a finite ordered set of homogenous elements
• Two dimensional Arrays• Multiply a Matrix
![Page 4: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/4.jpg)
Structures and Classes
• A structure is an aggregate data structure used to keep different pieces of information together as a single data record
• A structure is a collection of named fields whereas a class is a collection of named fields and methods that apply to objects of that class type.
• Class: Methods, Inheritance, constructor and destructor•
![Page 5: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/5.jpg)
Linked List
• Consists of items that are linked to each other• Each item on the list is associated with a
reference (pointer) that indicates where the next item is found
• A dynamic data structure: grows and shrinks as necessary at runtime
• There are no unused/empty locations
![Page 6: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/6.jpg)
Singly Linked List
• Simplest form of linked list• Linked list object holds a reference to the first
node on the list• Each node object consists of a reference to the
data object being stored, and a reference to the next node in the list
• The pointer to the first node in the list is referred to as the head pointer, because it points to the head node in the list.
![Page 7: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/7.jpg)
Singly Linked List Operations
With a linked list, there are a standard set of functions that operate on the list:– Creating the list
Initialize pointers to NULL;– Inserting nodes
Insert at beginning Insert at middle Insert at last
– Deleting nodes Delete from beginning, middle, last
– Traversing the list– Destroying the list
![Page 8: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/8.jpg)
Other list flavors
• Doubly-linked list– Each node has a pointer to its successor and its
predecessor. • Faster insert/delete, but more space.
• Circular list– The last node points back to the head.
• Sorted list– Items stored in sorted order.
![Page 9: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/9.jpg)
What is a Stack
• A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end called the TOP of the stack
• Data items are "popped" and "pushed" (retrieved and stored) from the top of the stack.
• Stacks normally have a maximum size.
• LIFO: Last In First Out
![Page 10: Data Structures](https://reader036.vdocuments.us/reader036/viewer/2022083004/56812c63550346895d90f6ef/html5/thumbnails/10.jpg)
Stack features• ORDERING: maintains order when elements added
(new elements are added to the end by default)
• OPERATIONS:– add element to end of list ('push')– remove element from end of list ('pop')– isEmpty()– isFull()– Top()
• Implementation of these operations