Write a program to create a structure of a Node, create a class Linked List. Implement all operations of a linked list as member function of this class.
∙ create_node(int);
∙ insert_begin();
∙ insert_pos();
∙ insert_last();
∙ delete_pos();
∙ sort();
∙ search();
∙ update();
∙ reverse();
∙ display();
Solution
{
int info;
struct node *next;
}*start;
/*
* Class Declaration
*/
class single_llist
{
public:
node* create_node(int);
void insert_begin();
void insert_pos();
void insert_last();
void delete_pos();
void sort();
void search();
void update();
void reverse();
void display();
single_llist()
{
start = NULL;
}
};
/*
* Main :contains menu
*/
main()
{
int choice, nodes, element, position, i;
single_llist sl;
start = NULL;
while (1)
{
cout
cout
cout
cout
cout
cout
cout
cout
cin>>choice;
switch(choice)
{
case 1:
cout
cout
break;
case 2:
cout
cout
break;
case 3:
cout
cout
break;
case 4:
cout
sl.sort();
cout
break;
case 5:
cout
break;
case 6:
cout
sl.update();
cout
break;
case 7:
cout
cout
break;
case 8:
cout
cout
break;
case 9:
cout
cout
break;
case 10:
cout
exit(1);
break;
default:
cout
}
}
}
/*
* Creating Node
*/
node *single_llist::create_node(int value) {
struct node *temp, *s;
temp = new(struct node);
if (temp == NULL)
{
cout
}
else
{
temp->info = value;
temp->next = NULL;
return temp;
}
}
/*
* Inserting element in beginning
*/
void single_llist::insert_begin()
{
int value;
cout>value;
struct node *temp, *p;
temp = create_node(value);
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else