Data Structures (CS301) Linked List and its implementation

Slides:



Advertisements
Similar presentations
Chapter 17 Linked Lists.
Advertisements

Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
Section 2.5 Single-Linked Lists. A linked list is useful for inserting and removing at arbitrary locations The ArrayList is limited because its add and.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Linked Lists. 2 Merge Sorted Lists Write an algorithm that merges two sorted linked lists The function should return a pointer to a single combined list.
Web Application Development Slides Credit Umair Javed LUMS.
Data Structures: A Pseudocode Approach with C
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
Linked Lists.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
B+ Trees Similar to B trees, with a few slight differences
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
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.
Lecture 14 Linked Lists 14-1 Richard Gesick. Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection.
1 Writing a Good Program 8. Elementary Data Structure.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Programming (OOP) Lecture No. 11.
CSC241 Object-Oriented Programming (OOP) Lecture No. 7.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees.
Linked Lists Objects->Connected->by->Pointers. What is a Linked List? List: a collection Linked: any individual item points to another item to connect.
“When we quit thinking primarily about ourselves and our own self-preservation, we undergo a truly heroic transformation of consciousness.” – Joseph Campbell.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
CSC241 Object-Oriented Programming (OOP) Lecture No. 5.
List Interface and Linked List Mrs. Furman March 25, 2010.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
CS 1430: Programming in C++ 1. Class StudentList class StudentList { private: int numStudents; Student students[MAX_SIZE]; int find(const Student& s)
Java linked list.
CSCS-200 Data Structure and Algorithms Lecture
Binary Search Trees (BST) Let’s look at some pics …and some code.
CS1020 L AB 3 (L INKED L IST ) Problem 1: Balls Problem 2: Josephine Problem 3: Keyboard.
Lecture No.04 Data Structures Dr. Sohail Aslam
CS1220 Midterm Review.
CS505 Data Structures and Algorithms
CS2006- Data Structures I Chapter 5 Linked Lists I.
List ADT & Linked Lists.
Lecture No.03 Data Structures Dr. Sohail Aslam
Programming Abstractions
8-1.
Threaded Trees Binary trees have a lot of wasted space: the leaf nodes each have 2 null pointers We can use these pointers to help us in inorder traversals.
The Singly-Linked Structure
Pointers and Linked Lists
8-1.
Chapter 18: Linked Lists.
Linked List (Part I) Data structure.
Object Oriented Programming (OOP) Lecture No. 9
Trees.
Recitation 5 CS0445 Data Structures
Object-Oriented Programming (OOP) Lecture No. 14
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Programming Abstractions
A List Implementation That Links Data
slides created by Marty Stepp and Hélène Martin
Object-Oriented Programming (OOP) Lecture No. 22
Lecture 14 Linked Lists CSE /26/2018.
Linked Lists.
A3 is due after the break, but start on it NOW
Web Design & Development Lecture 4
Lecture No.02 Data Structures Dr. Sohail Aslam
Data Structures & Algorithms
Object Oriented Programming (OOP) Lecture No. 11
Object oriented programming (OOP) Lecture No. 6
slides created by Marty Stepp
A List Implementation That Links Data
Presentation transcript:

Data Structures (CS301) Linked List and its implementation Virtual University of Pakistan

Objective Objective of this presentation is to teach you the concept and implementation of list data structure by using linked list Virtual University PAkistan

What is a linked list? It is a dynamic data structure. Linked list consist of series of nodes Chain the nodes together to form a linked list Structure of each node is like the one given below Data Next 1000 Virtual University PAkistan

Linked list Analogy to a train Insert a node with value ‘2’ in existing list

Graphical Representation of Linked List Picture of our list (2, 6, 8, 7, 1) stored as a linked list: 8000 1000 2 3000 6 5000 8 2000 7 6000 1 headNode lastcurrentNode currentNode Size = 5 Virtual University PAkistan

C++ Code for linked list We need two classes to implement linked list: Node Class List class In addition to linked list class and node class, we also need a function main() from where execution of our program will start. Virtual University PAkistan

Example Create a list of students using linked list data structure.

Defining a Node class (Student) class Student { char* Rollno; Student *NextStudent; public: Student() // Constructor Rollno=""; NextStudent=NULL; } void Set_RollNo(char* rno) //Setter function to set data member Rollno Rollno = rno; char* Get_RollNo() //Getter function to get value of Rollno return Rollno;

Node class (Student) Con’t void SetNextStudent(Student *NS) //Setter function to set NextStudent { NextStudent = NS; } Student* getNextStudent() //Getter function to get value of NextStudent return NextStudent; };

StudentList class class StudentList { private: Student *HeadStudent,*CurrentStudent; public: StudentList::StudentList() // Constructor HeadStudent = new Student(); HeadStudent->SetNextStudent(NULL); CurrentStudent = NULL; } HeadStudent 8000 8000 CurrentStudent NULL

Add function void Add_Student(char* rno) // Function to add students in list { Student *NewStudent = new Student(); NewStudent->Set_RollNo(rno); NewStudent->SetNextStudent(NULL); if(CurrentStudent == NULL) HeadStudent = NewStudent; CurrentStudent = NewStudent; } else CurrentStudent->SetNextStudent(NewStudent); CurrentStudent= NewStudent; cout<<CurrentStudent->Get_RollNo();

Main() function main() // Main() function { StudentList S; S.Add_Student("MC000000000."); cout<<endl; S.Add_Student("MC000000001."); S.Add_Student("MC000000002."); system("pause"); }

Output

Your Tasks Task 1: Remove the following line from end of Add() function. cout<<CurrentStudent->Get_RollNo(); Task 2: Add traverse (display) function to display roll number of students. Task3: Add more attributes (name, GPA, semester etc) in student class and make changes in your code accordingly.