Saturday 16 September 2017

Insertion/Deletion/Count all record In Linklist in C/C++

#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
struct node
{
int info;
node *link;
};
void insert(node **start,int num)
{
node *temp=new node;

temp->info=num;
temp->link=*(start);
*(start)=temp;
}


void remove(node **start,int num,int pos)
{
cout<<"Delete From Starting:\n";
cout<<"Delete From Last:\n";
cout<<"Delete From POS:";
int ch;
cin>>ch;
}

void count(node *start)
{
int count=0;
node *temp=start;
while(temp!=NULL)
{
count++;
temp=temp->link;
}
cout<<count;
}

int lengthRecursion(node *start)
{
int count=0;
while(start!=NULL)
{
count+=1;
return count+lengthRecursion(start->link);
}
}
main()
{
node *start=NULL;
node *prev=NULL;
system("cls");
AGAIN:
system("cls");
cout<<"1. Add Record:\n";
cout<<"2. Delete Record:\n";
cout<<"3. Count Record:\n";
cout<<"4. Count Record(RECURSION):\n";
int ch;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Number :";
int num;
cin>>num;
insert(&start,num);
cout<<"Recored Updated:";
getch();
goto AGAIN;
break;
case 2:
int pos;
cin>>pos;
remove(&start,num,pos);
goto AGAIN;
break;
case 3:
count(start);
getch();
goto AGAIN;
break;
case 4:
int ca;
ca=lengthRecursion(start);
cout<<ca;
getch();
goto AGAIN;
break;

default:

cout<<"Wrong Choice:";

}

}

No comments:

Post a Comment

Amazon1Ads