Lab_7_adding_node_at_the_beggining_in_singly_linked_list_using_c++
Lab_7_adding_node_at_the_beggining_in_singly_linked_list_using_c++
/*
* A program that demonistrates implementation
* of linked and different operations on linked list.
*/
using namespace std;
struct Node{
int id;
char name[15];
int age;
Node* next;
}*head=NULL;
Node* getNode(){
Node* temp=new Node;
cout<<"Enter Id:";
cin>>temp->id;
cout<<"Enter name:";
cin>>temp->name;
cout<<"Enter Age:";
cin>>temp->age;
temp->next=NULL;
return temp;
}
int size(){
Node*curr=head;
int count=0;
while(curr!=NULL){
count++;
curr=curr->next;
}
return count;
}
void display(){
Node*curr=head;
cout<<endl<<"Displaying all the student data"<<endl;
while(curr!=NULL){
cout<<"Student ID"<<"\t"<<"Student Name"<<"\t"<<"Student Age"<<endl;
cout<<curr->id<<"\t \t"<<curr->name<<"\t \t"<<curr->age<<endl;
curr=curr->next;
cout<<endl;
}
}
void insertAtBeginning(){
Node *temp=new Node;
}
else{
temp->next=head;
}
head=temp;
}
int main(int argc, char** argv) {
int choice;
int index;
do{
cout<<"WELCOME TO LINKED LIST OPERATION EXAMPLE"<<endl;
cout<<"======MENU==========\n";
cout<<"Press 1 to insert node at the beginning.\n";
cout<<"Press 2 to display all nodes.\n";
cout<<"Press 3 to display the size of the linked list.\n";
cout<<"Press 4 to close the program.\n";
}while(choice!=4);
return 0;
}