CHETAN JAISWAL
0901CS211041
#include <iostream>
#include <string>
using namespace std;
#define null 0
class Student {
public:
string name;
int age;
float gpa;
Student(string name, int age, float gpa) {
this->name = name;
this->age = age;
this->gpa = gpa;
};
class Node {
public:
Student* stu;
Node* next;
Node(Student* stu) {
this->stu = stu;
next = null;
};
class LinkedList {
private:
Node* head;
Node* tail;
int size;
public:
LinkedList() {
head = null;
tail = null;
size = 0;
int getSize() {
return size;
void append(string name, int age, float gpa) {
Student *stud = new Student(name, age, gpa);
Node *node = new Node(stud);
if(head == null) {
head = node;
tail = node;
} else {
tail->next = node;
tail = node;
size++;
void prepend(string name, int age, float gpa) {
Student *stud = new Student(name, age, gpa);
Node *node = new Node(stud);
if(head == null) {
head = node;
tail = node;
} else {
node->next = head;
head = node;
size++;
void removeStu(string name) {
if(head != null) {
Node *current = head;
if(current->stu->name == name) {
delete current;
} else {
while(current != null) {
if(current->next->stu->name == name) {
current->next = current->next->next;
break;
} else {
current = current->next;
size--;
void removeHead() {
if(head != null) {
Node *current = head;
head = head->next;
delete current;
size--;
}
void display() {
Node *current = head;
while(current != null) {
cout << current->stu->name << ", " << current->stu->age << ", " << current-
>stu->gpa << endl;
current = current->next;
cout << "*" << getSize() << endl;
cout << endl;
void run() {
append("chetan", 17, 3.1);
append("aayush", 22, 2.8);
append("kishan", 18, 1.7);
prepend("rohit", 21, 3.5);
display();
remove("chetan");
display();
void destroy() {
Node* current;
while(head != null) {
current = head->next;
delete head;
head = current;
head = null;
tail = null;
size = 0;
}
~LinkedList() {
destroy();
};
int main() {
LinkedList list;
list.run();
return 0; }
OUTPUT :