Group C Assign 19 Pranav Aher
Group C Assign 19 Pranav Aher
Assignment No 8
Title:
Write C++ program to implement Singly Linked List and operations on it-
Marks: Sign:
Input:
/*
#include <iostream>
using namespace std;
int main()
{
int *ptr = NULL; // Pointer initialized with null
ptr = new int; // Request memory for the variable
*ptr = 12345; // Store value at allocated address
cout << "Value of Pointer Variable *ptr : " << *ptr << endl;
cout << "address of Pointer Variable *ptr : " << ptr;
delete ptr; // free up the memory.
return 0;
}
*/
/*
// Making a node struct containing a data int and a pointer
// to another node
struct Node {
int data;
Node *next;
};
class LinkedList
{
// Head pointer
Node* head;
public:
// default constructor. Initializing head pointer
LinkedList()
{
head = NULL;
}
// Else loop over the list and search for the node to delete
Node* temp = head;
while(temp->next!= NULL)
{
// When node is found, delete the node and modify the pointers
if (temp->next->data == val)
{
Node* temp_ptr = temp->next->next;
delete temp->next;
temp->next = temp_ptr;
return;
}
temp = temp->next;
}
void display()
{
Node* temp = head;
while(temp != NULL)
{
cout << temp->data << " ";
temp = temp->next;
}
cout << endl;
}
};
int main() {
LinkedList l;
// inserting elements
l.insert(6);
l.insert(9);
l.insert(1);
l.insert(3);
l.insert(7);
cout << "Current Linked List: ";
l.display();
Output:
1. Add Member
2. Display Members
3. Display total number of members of club
4. Delete Member
5. Concatenate two lists
6. Exit
Enter your choice : 1