#include
#include
#include
using namespace std;
struct student{
int x;
student *next,*tail;
}*current, *start, *temp;
void insert(int n)
{
if (start == NULL)
{
start = new student;
start->x = n;
start->next = NULL;
start->tail = NULL;
}
else{
current = start;
while (current->next != NULL)
{
current = current->next;
}
temp = new student;
temp->x = n;
temp->next = NULL;
current->next = temp;
temp->tail = current;
}
}
void print()
{
if (start == NULL)
{
cout << "ERROR: LINK LIST IS EMPTY \n";
}
else{
current = start;
while (current->next != NULL)
{
cout << current->x << endl;
current = current->next;
}
cout << current->x << endl;
}
}
void search(int n)
{
int flag = 2;
if (start == NULL)
{
cout << "Error:LINK LIST IS EMPTY \n";
}
else
{
current = start;
while (current->next != NULL)
{
if (current->x == n)
{
cout << " FOUND \n";
flag = 1;
current = current->next;
}
else{
current = current->next;
}
}
if (flag != 1)
{
cout << "ERROR: NOT FOUND \n";
}
}
}
int count()
{
int x = 1;
if (start == NULL)
{
cout << " ERROR:LINK LIST IS EMPTY \n";
}
else
{
current = start;
while (current->next != NULL)
{
x++;
current = current->next;
}
cout << "count = " << x << endl;
return x;
}
}
void insertfirst(int n)
{
if (start == NULL)
{
start = new student;
start->x = n;
start->next = NULL;
start->tail = NULL;
}
else
{
current = start;
start = new student;
start->x = n;
start->next = current;
start->tail = NULL;
current->tail = start;
}
}
void insertionmiddle(int n)
{
int p;
if (start == NULL)
{
cout << "There is no node in the libarary so there is no insertion of your choice hence the node you enter is the the first node \n";
cout<< "P.S You can ignore the big statement"< start = new student;
start->x = n;
start->next =start->tail= NULL;
}
else{
cout << "Enter a position on which point you want to insert a value \n";
cin >> p;
if (count() > p){
cout << "you have enter an invalid position \n";
}
else{
current = start;
for (int i = 1; i < p ; i++){
current = current->next;
}
temp = new student;
temp->x = n;
temp->next = current->next;
temp->tail = current;
current->next = temp;
}
}
}
void delse( int del,int c)
{
current = start;
for (int i = 1; i <= c; i++)
{
if (current->x == del)
{
temp->next = current->next;
current->tail = temp;
delete current;
}
temp = current;
current=current->next;
}
}
void delfi()
{
current = start;
start = start->next;
start->tail = NULL;
delete current;
}
void delen()
{
current = start;
while (current->next = NULL){
temp = current;
current = current->next;
}
temp->next = NULL;
delete current;
}
void delpo(int n){
current = start;
for(int i = 1; i < n; i++){
temp = current;
current = current->next;
}
temp->next = current->next;
temp->tail = current;
delete current;
}
int main()
{
system("COLOR F0");
string s;
int x;
do{
system("CLS");
cout << "for insertion press 1 \n";
cout << "for deletion press 2 \n";
cout << "for searching press 3 \n";
cout << "for counting total number of node press 4 \n";
cout << "for printing press 5 \n";
cin >> x;
switch (x)
{
case 1:{
int x, n, p;
string s;
do{
system("CLS");
cout << "For insertion at start press 1 \n";
cout << "For insertion at the end press 2\n";
cout << "For insertion at your choice point press 3\n";
cin >> x;
switch (x){
case 1:
{
cout << "enter a number \n";
insertfirst(n);
break;
}
case 2:
{cout << "enter a number \n";
cin >> n;
insert(n);
break; }
case 3:{
cout << "enter a number \n";
cin >> n;
insertionmiddle(n);
break;
}
default:
{
cout << "Hey, you have press an invalid key -_- \n";
}
}
cout << "For more insertion press y else n Okay? \n";
cin >> s;
} while (s == "y");
break;}
case 2:
{
int x, n, p;
string s;
do{
system("CLS");
cout << "deletion at start press 1 \n";
cout << "deletion at the end press 2\n";
cout << "deletion at your choice point press 3\n";
cin >> x;
switch (x){
case 1:{
delfi();
break;
}
case 2:{
delen();
break;
}
case 3:{
cout << "Kindly enter the position on which point you want to delete a value \n";
cin >> p;
delpo(p);
break;
}
default:
{
cout << "Oh please! you have press invalid key \n";
}}
cout << "For more deletion press y else n \n";
cin >> s;}
while (s == "y");
break;}
case 3:
{
int n;
cout << "ENTER A NUMBER FOR SEARCHING \n";
cin >> n;
search(n);
break;}
case 4:{
cout<<"total number of nodes are "< break;}
case 5:
{
print();
break;
}
default:{
cout << "What the hell! you have entered an invalid key \n";
}
}
system("CLS");
cout << "For more operation press y else n \n";
cin >> s;}
while (s == "y");
system("pause");
return 0;
}
#include
#include
using namespace std;
struct student{
int x;
student *next,*tail;
}*current, *start, *temp;
void insert(int n)
{
if (start == NULL)
{
start = new student;
start->x = n;
start->next = NULL;
start->tail = NULL;
}
else{
current = start;
while (current->next != NULL)
{
current = current->next;
}
temp = new student;
temp->x = n;
temp->next = NULL;
current->next = temp;
temp->tail = current;
}
}
void print()
{
if (start == NULL)
{
cout << "ERROR: LINK LIST IS EMPTY \n";
}
else{
current = start;
while (current->next != NULL)
{
cout << current->x << endl;
current = current->next;
}
cout << current->x << endl;
}
}
void search(int n)
{
int flag = 2;
if (start == NULL)
{
cout << "Error:LINK LIST IS EMPTY \n";
}
else
{
current = start;
while (current->next != NULL)
{
if (current->x == n)
{
cout << " FOUND \n";
flag = 1;
current = current->next;
}
else{
current = current->next;
}
}
if (flag != 1)
{
cout << "ERROR: NOT FOUND \n";
}
}
}
int count()
{
int x = 1;
if (start == NULL)
{
cout << " ERROR:LINK LIST IS EMPTY \n";
}
else
{
current = start;
while (current->next != NULL)
{
x++;
current = current->next;
}
cout << "count = " << x << endl;
return x;
}
}
void insertfirst(int n)
{
if (start == NULL)
{
start = new student;
start->x = n;
start->next = NULL;
start->tail = NULL;
}
else
{
current = start;
start = new student;
start->x = n;
start->next = current;
start->tail = NULL;
current->tail = start;
}
}
void insertionmiddle(int n)
{
int p;
if (start == NULL)
{
cout << "There is no node in the libarary so there is no insertion of your choice hence the node you enter is the the first node \n";
cout<< "P.S You can ignore the big statement"<
start->x = n;
start->next =start->tail= NULL;
}
else{
cout << "Enter a position on which point you want to insert a value \n";
cin >> p;
if (count() > p){
cout << "you have enter an invalid position \n";
}
else{
current = start;
for (int i = 1; i < p ; i++){
current = current->next;
}
temp = new student;
temp->x = n;
temp->next = current->next;
temp->tail = current;
current->next = temp;
}
}
}
void delse( int del,int c)
{
current = start;
for (int i = 1; i <= c; i++)
{
if (current->x == del)
{
temp->next = current->next;
current->tail = temp;
delete current;
}
temp = current;
current=current->next;
}
}
void delfi()
{
current = start;
start = start->next;
start->tail = NULL;
delete current;
}
void delen()
{
current = start;
while (current->next = NULL){
temp = current;
current = current->next;
}
temp->next = NULL;
delete current;
}
void delpo(int n){
current = start;
for(int i = 1; i < n; i++){
temp = current;
current = current->next;
}
temp->next = current->next;
temp->tail = current;
delete current;
}
int main()
{
system("COLOR F0");
string s;
int x;
do{
system("CLS");
cout << "for insertion press 1 \n";
cout << "for deletion press 2 \n";
cout << "for searching press 3 \n";
cout << "for counting total number of node press 4 \n";
cout << "for printing press 5 \n";
cin >> x;
switch (x)
{
case 1:{
int x, n, p;
string s;
do{
system("CLS");
cout << "For insertion at start press 1 \n";
cout << "For insertion at the end press 2\n";
cout << "For insertion at your choice point press 3\n";
cin >> x;
switch (x){
case 1:
{
cout << "enter a number \n";
insertfirst(n);
break;
}
case 2:
{cout << "enter a number \n";
cin >> n;
insert(n);
break; }
case 3:{
cout << "enter a number \n";
cin >> n;
insertionmiddle(n);
break;
}
default:
{
cout << "Hey, you have press an invalid key -_- \n";
}
}
cout << "For more insertion press y else n Okay? \n";
cin >> s;
} while (s == "y");
break;}
case 2:
{
int x, n, p;
string s;
do{
system("CLS");
cout << "deletion at start press 1 \n";
cout << "deletion at the end press 2\n";
cout << "deletion at your choice point press 3\n";
cin >> x;
switch (x){
case 1:{
delfi();
break;
}
case 2:{
delen();
break;
}
case 3:{
cout << "Kindly enter the position on which point you want to delete a value \n";
cin >> p;
delpo(p);
break;
}
default:
{
cout << "Oh please! you have press invalid key \n";
}}
cout << "For more deletion press y else n \n";
cin >> s;}
while (s == "y");
break;}
case 3:
{
int n;
cout << "ENTER A NUMBER FOR SEARCHING \n";
cin >> n;
search(n);
break;}
case 4:{
cout<<"total number of nodes are "<
case 5:
{
print();
break;
}
default:{
cout << "What the hell! you have entered an invalid key \n";
}
}
system("CLS");
cout << "For more operation press y else n \n";
cin >> s;}
while (s == "y");
system("pause");
return 0;
}
No comments:
Post a Comment