100 likes | 215 Views
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!.
E N D
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! 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
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
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
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.
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
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.
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 endcalled 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
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