Introduction to Linked List Data Structure Implementation
This presentation focuses on teaching the concept and implementation of linked list data structures using C++ at Virtual University of Pakistan. It covers creating, inserting, and manipulating nodes in a linked list. The importance of node and list classes, along with a main function, is emphasized for effective implementation. Additionally, a practical example of creating a linked list of students is demonstrated.
Uploaded on Apr 13, 2025 | 0 Views
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Objective of this presentation is to teach you the concept and implementation of list data structure by using linked list Virtual University PAkistan
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 Next Next Data Data 1000 1000 Virtual University PAkistan
Insert a node with value 2 in existing list
Picture of our list (2, 6, 8, 7, 1) stored as a linked list: lastcurrentNode lastcurrentNode headNode headNode currentNode currentNode 2 2 6 6 8 8 7 7 1 1 Size = 5 5 Size = 1000 1000 3000 3000 5000 5000 2000 2000 6000 6000 8000 1000 3000 5000 2000 6000 Virtual University PAkistan
We need two classes to implement linked list: 1. Node Class 2. 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
class Student { char* Rollno; Student *NextStudent; public: { Rollno=""; NextStudent=NULL; } class Student Student() Student() // Constructor // Constructor void { Rollno = rno; } void Set_RollNo Set_RollNo(char* rno) (char* rno) //Setter function to set data member //Setter function to set data member Rollno Rollno char* Get_RollNo() { return Rollno; } char* Get_RollNo() //Getter function to get value of //Getter function to get value of Rollno Rollno
void SetNextStudent(Student *NS) //Setter function to set NextStudent { NextStudent = NS; } Student* getNextStudent() //Getter function to get value of NextStudent { return NextStudent; } }; //Setter function to set NextStudent //Getter function to get value of NextStudent
class StudentList { private: Student *HeadStudent,*CurrentStudent; public: class StudentList StudentList::StudentList() StudentList::StudentList() // Constructor // Constructor { HeadStudent = new Student(); HeadStudent->SetNextStudent(NULL); HeadStudent 8000 8000 8000 CurrentStudent CurrentStudent = NULL; } NULL NULL
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(); } // Function to add students in list
main() // Main() function { StudentList S; S.Add_Student("MC000000000."); cout<<endl; S.Add_Student("MC000000001."); cout<<endl; S.Add_Student("MC000000002."); cout<<endl; system("pause"); }
Task 1: Remove the following line from end of Add() function. cout<<CurrentStudent Task 1: cout<<CurrentStudent- ->Get_RollNo(); >Get_RollNo(); Task 2: Add traverse (display) function to display roll number of students. Task 2: Task3: student class and make changes in your code accordingly. Task3: Add more attributes (name, GPA, semester etc) in