Professional Documents
Culture Documents
1)Length of Linklist
2)Print Linklist
3)Reverse print Linklist
4)Largest Element Linklist
5)Tower of Hanoi
6)Recursive solution for sequential search
7)Recursive solution for
A1=6 A(n)=2*A(n-1)+4
Singly:
int len(node * temp ,int length)
{
If(temp->next !=NULL)
{
len(temp->next,length+1);
}
Return length;
}
Doubly:
int len(node * temp ,int length)
{
If(temp->next !=NULL)
{
len(temp->next,length+1);
}
Return length;
}
Circular:
Int len(node * temp ,int length)
{
If(temp->next !=head)
{
len(temp->next,length+1);
}
Return length;
}
Print Linklist
Singly:
Void display(node *temp)
{
If(temp->next!=NULL)
{
Cout<<temp->data;
display(temp->next);
}
Doubly:
Void display(node *temp)
{
If(temp->next!=NULL)
{
Cout<<temp->data;
display(temp->next);
}
Circular:
Void display(node *temp)
{
If(temp->next!=head)
{
Cout<<temp->data;
display(temp->next);
}
}
Reverse Print
Singly:
If(temp->next !=NULL)
R_prnt(temp->next);
Cout<<temp->data;
Doubly:
If(temp->prev !=head)
Cout<<temp->data;
R_prnt(temp->prev);
Circular:
Void r_prnt(node *temp)
If(temp->tail !=head)
Cout<<temp->data;
R_prnt(temp->prev);}
Max=temp->data;
If(temp->next != NULL)
max_el(temp->next,max);
Tower of Hanoi
Int moves=0;
Moves++;
If(m==1){cout<<”Move disk”<<m<<”from”<<a<<”to”<<c;}
Else {
Hanoi(m-1,a,c,b);
cout<<”Move disk”<<m<<”from”<<a<<”to”<<c;
Hanoi(m-1,b,a,c);
If(index!=max)
If(arr[index]==data)
Return data;
Else
Search(arr,index+1,max,data);
Prototype
{
If(x=0) arr[index]=0;
Return arr;