0% found this document useful (0 votes)
5 views3 pages

Circular Linked List Operations in C++

dsa

Uploaded by

kartikchauhan190
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Circular Linked List Operations in C++

dsa

Uploaded by

kartikchauhan190
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment

AIM-Create circular linked list having information about a college and perform
Insertion at front perform Deletion at end.

THEORY-

CODE-
#include <iostream>

#include <cstring>

using namespace std;

struct College {

char name[50];

char address[100];

College* next;

};

College* createNode(const char name[], const char address[]) {

College* newNode = new College;

strcpy(newNode->name, name);

strcpy(newNode->address, address);

newNode->next = nullptr;

return newNode;

void insertAtFront(College** head, const char name[], const char address[]) {

College* newNode = createNode(name, address);

if (*head == nullptr) {

newNode->next = newNode;
*head = newNode;

} else {

College* temp = *head;

while (temp->next != *head) {

temp = temp->next;

newNode->next = *head;

temp->next = newNode;

*head = newNode;

void deleteAtEnd(College** head) {

if (*head == nullptr) {

cout << "The list is empty." << endl;

return;

College* temp = *head;

College* prev = nullptr;

if (temp->next == *head) {

delete temp;

*head = nullptr;

} else {

while (temp->next != *head) {

prev = temp;

temp = temp->next;

prev->next = *head;

delete temp;

void displayList(College* head) {


if (head == nullptr) {

cout << "The list is empty." << endl;

return;

College* temp = head;

do {

cout << "College Name: " << temp->name << ", Address: " << temp->address << endl;

temp = temp->next;

} while (temp != head);

int main() {

College* head = nullptr;

insertAtFront(&head, "DELHI College", "1 College St.");

insertAtFront(&head, "GGSIPU University", "2 University Ave.");

insertAtFront(&head, "MAIT Institute", "3 Institute Rd.");

cout << "Circular Linked List after insertion at the front:" << endl;

displayList(head);

deleteAtEnd(&head);

cout << "\nCircular Linked List after deletion at the end:" << endl;

displayList(head);

return 0;

Output-

You might also like