Write a menu driven program to perform the following operations in a header linked
list by using suitable user defined functions for each case. The head node keeps the
count of the total number of nodes in the list. The data node keeps the student
information: Name, Roll No, CGPA, Address_City, Branch.
1. Create
2. Display student information
3. Display the total number of nodes (in O(1) time)
4. Display the students’ details belonging to a particular branch
5. Display the students’ details securing > 7.5 CGPA and belonging to a given
branch.
#include <iostream>
using namespace std;
struct Node_A
{
int details;
struct Node_A *next;
};
void push(struct Node_A** head, int node_details)
{
struct Node_A* newNode_A = new Node_A;
newNode_A->details = node_details;
newNode_A->next = (*head);
(*head) = newNode_A;
}
void insert(struct Node_A* prev_node, int node_data)
{
if (prev_node == NULL)
{
cout<<"the given previous node is required,cannot be NULL"; return; }
struct Node_A* newNode_A =new Node_A;
newNode_A->details = node_data;
newNode_A->next = prev_node->next;
prev_node->next = newNode_A;
}
void append(struct Node_A** head, int node_details)
{
struct Node_A* newNode_A = new Node_A;
struct Node_A *last = *head;
newNode_A->details = node_details;
newNode_A->next = NULL;
if (*head == NULL)
{
*head = newNode_A;
return;
}
while (last->next != NULL)
last = last->next;
last->next = newNode_A;
return;
}
void showList(struct Node_A *node)
{
while (node != NULL)
{
cout<<node->details<<"-->";
node = node->next;
}
if(node== NULL)
cout<<"null";
}
int main()
{
struct Node_A* head = NULL;
//Insert students details
append(&head, 10); // Insert Total number of nodes
push(&head, 20); // Insert students rollno.
push(&head, 8); // Insert CGPA.
push(&head, 10001); // Insert address.
push(&head,112);//Insert branch.
cout<<"The students details are: "<<endl;
cout<<"Name "<<"RollNo "<<"Address "<<"CGPA "<<"branch "<<"total_nodes"<<endl;
cout<<"Candy -->";
showList(head);
return 0;
}
Comments
Leave a comment