linklist 2
include <iostream> using namespace std;
struct Node {
int data;
Node next;
};
void insert(int value, Node” Shead) {
Node newNode = new Node;
newNode->data = value;
newNode->next = head;
head newNode;
}
void remove(int value, Node &head) { Node current = head; Node previous = NULL;
while (current I= NULL && current->data != value) {
previous current;
current current->next;
}
if (current == NULL) {
return;
}
if (previous == NULL) { head current->next; } else {
previous->next = current->next;
}
delete current;
}
void print (Node” &head) { Node current = head;
}
void print (Node* &head) { Node current = head;
while (current I= NULL) {
cout << current->data << current = current->next;
}
cout << endl;
}
int main()
Node head-NULL;
int cnt, choice, element, data, pos; while(cnt<1000){ cout<<“1. Insert value:”<<endl; cout<<“2. Delete value:”<<endl; cout<<“3. print “<<endl; cout<<“Enter choice: “;
cin>>choice;
case 1:
cout<<“\nEnter the data: “;
cin>>data;
insert(data, head);
break;
case 2:
cout<<“Enter the value you want to delete : “; cin>>pos;
remove(pos, head);
break;
case 3:
print (head); break;
cout<<endl; cnt++;