search element from sort link list


//searching an element from sorted link list
#include<iostream.h>
#include<conio.h>
typedef struct node
{
int data;
struct node *link;
}NODE;
void main()
{
NODE *ptr,*prev,*start;
start=NULL;
clrscr();
cout<<"\nEnter 10 elements in array\n";
for(int i=0;i<10;i++)
{
ptr=new NODE();
cin>>ptr->data;
ptr->link=NULL;
if(start==NULL)
{
start=ptr;
}
else
{
prev->link=ptr;
}
prev=ptr;
}
//searching elements from sort list
int item;
cout<<"\nEnter element to be search \n";
cin>>item;
ptr=start;
int f=0;
NODE *loc;
loc=NULL;
while(ptr!=NULL)
{
if(item>ptr->data)
{
ptr=ptr->link;
}
else if(item==ptr->data)
{
f=1;
loc=ptr;
break;
}
else
{
loc=NULL;
break;
}
}
if(f==1)
cout<<"\nitem searched successfully at "<<loc;
else
cout<<"\nitem not find at"<<loc;
getch();
}

******output*******

Enter 10 elements in array
2
3
14
25
35
62
75
80
82
85

Enter element to be search
82

item searched successfully at 0x8fa50f5a

searching element in unsorted link list


//searching an element from an unsorted link list
#include<iostream.h>
#include<conio.h>
typedef struct node
{
int data;
struct node *link;
}NODE;
void main()
{
NODE *ptr,*prev,*start;
start=NULL;
clrscr();
cout<<"\nEnter 10 elements in array\n";
for(int i=0;i<10;i++)
{
ptr=new NODE();
cin>>ptr->data;
ptr->link=NULL;
if(start==NULL)
{
start=ptr;
}
else
{
prev->link=ptr;
}
prev=ptr;
}
//searching elements from unsort list
int item;
cout<<"\nEnter element to be search \n";
cin>>item;
ptr=start;
int f=0;
NODE *loc;
for(i=0;i<10;i++,ptr=ptr->link)
{
if(item==ptr->data)
{
f=1;
loc=ptr;
break;
}
}
if(f==1)
cout<<"\nitem searched successfully at "<<loc;
else
cout<<"\nitem not find";
getch();
}

*******output*******

Enter 10 elements in array
2
3
15
65
48
9
62
14
75
33

Enter element to be search
62

item searched successfully at 0x8fa40f46

link list in c



//implementation of link list in c
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
typedef struct node
{
int data;
struct node *link;
}NODE;
NODE *ptr,*start,*prev;
int i;
clrscr();
start=NULL;
printf("\nEnter 10 elements in array\n");
for(i=0;i<10;i++)
{
ptr=(NODE *)malloc(sizeof(NODE *));
scanf("%d",&ptr->data);
ptr->link=NULL;
if(start==NULL)
{
start=ptr;
}
else
{
prev->link=ptr;
}
prev=ptr;
}
ptr=start;
printf("\nElements in array\n");
for(i=0;i<10;i++,ptr=ptr->link)
printf("\na[%d]=%d",i,ptr->data);
getch();
}

*****output******



link list in cpp


//implementation of link list in cpp
#include<iostream.h>
#include<conio.h>
void main()
{
typedef struct node
{
int data;
struct node *link;
}NODE;
NODE *ptr,*start,*prev;
int i;
clrscr();
start=NULL;
cout<<"\nEnter 10 elements in array\n";
for(i=0;i<10;i++)
{
ptr=new NODE();
cin>>ptr->data;
ptr->link=NULL;
if(start==NULL)
{
start=ptr;
}
else
{
prev->link=ptr;
}
prev=ptr;
}
ptr=start;
cout<<"\nElements in array\n";
for(i=0;i<10;i++,ptr=ptr->link)
cout<<"\na["<<i<<"]="<<ptr->data;
getch();
}
*******output********






selection sort




//implementing selection sort
#include<iostream.h>
#include<conio.h>
void main()
{
int a[20],ptr,i,k,loc,min,temp;
clrscr();
cout<<"Enter the elements in array";
for(i=1;i<=10;i++)
{
cin>>a[i];
}
for(i=1;i<=10;i++)
{
min=a[i];
loc=i;
ptr=i+1;
while(ptr<=10)
{
if(min>a[ptr])
{
min=a[ptr];
loc=ptr;
}
ptr++;
}

temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}
cout<<"Sorted array is\n";
for(i=1;i<=10;i++)
cout<<"\na["<<i<<"]="<<a[i];
getch();
}
********output**********












shell sort



//implement shell sorting
#include<iostream.h>
#include<math.h>
#include<conio.h>
const int size=10;
void main()
{
int a[size],gap,i,j,temp;
clrscr();
cout<<"\n\Enter elements in array\n";
for(i=0;i<size;i++)
cin>>a[i];
gap=size/2;
while(gap>0)
{
i=gap;
while(i<size)
{
temp=a[i];
j=i;
while(j>=gap && temp<a[j-gap])
{
a[j]=a[j-gap];
j=j-gap;
}
a[j]=temp;
i++;
}
gap=ceil(gap/2);
}
i=0;
cout<<"\nsorted array by shell sorting is\n";
while(i<size)
{
cout<<"\na["<<i<<"]"<<a[i];
i++;
}
getch();
}
*******output*******







radix sort


//implementation of radix sort for number by linked list
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void radix(int [],int ,int);
void main()
{
int a[100],n,m,i;
printf("\nEnter no of no and no of digits\n");
scanf("%d%d",&n,&m);
printf("\nEnter elemets\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
radix(a,n,m);
printf("\nSorted array is\n");
for(i=0;i<n;i++)
printf("\na[%d]=%d",i,a[i]);
getch();
}
void radix(int a[],int n,int m)
{
typedef struct node
{
int data;
struct node *next;
}NODE;
NODE *ptr,*prev,*start;
NODE *front[10],*rear[10];
int i,j,k=1,y,p;
start=NULL;
for(i=0;i<n;i++)
{
ptr=(NODE *)malloc(sizeof(NODE *));
ptr->data=a[i];
ptr->next=NULL;
if(start==NULL)
start=ptr;
else
prev->next=ptr;
prev=ptr;
}
for(i=1;i<=m;i++)
{
for(j=0;j<10;j++)
front[j]=NULL;
ptr=start;
while(ptr!=NULL)
{
y=((ptr->data)/k)%10;
if(front[y]==NULL)
{
front[y]=ptr;
rear[y]=ptr;
}
else
{
rear[y]->next=ptr;
rear[y]=ptr;
}
ptr=ptr->next;
}
start=NULL;
for(j=0;j<10;j++)
{
if(front[j]!=NULL)
{
if(start==NULL)
start=front[j];
else
rear[p]->next=front[j];
p=j;
}
}
rear[p]->next=NULL;
k=k*10;
}
ptr=start;
for(i=0;i<n;i++,ptr=ptr->next)
a[i]=ptr->data;

}
*******output*********




//quick sort
#include<iostream.h>
#include<conio.h>
int quick(int [],int,int,int);
void main()
{
int top=-1,a[10],n=10,lower[10],upper[10],beg,end,loc;
clrscr();
cout<<"Enter the elements in array";
for(int i=0;i<10;i++)
cin>>a[i];
if(n>0)
{
top=top+1;
lower[0]=0;
upper[0]=n-1;
}
while(top!=-1)
{
beg=lower[top];
end=upper[top];
top=top-1;
loc=quick(a,n,beg,end);
if(beg<loc-1)
{
top=top+1;
lower[top]=beg;
upper[top]=loc-1;

}
if(loc+1<end)
{
top=top+1;
lower[top]=loc+1;
upper[top]=end;
}


}

cout<<"\nSorted array is";
for(i=0;i<10;i++)
cout<<"\n"<<a[i];
getch();

}
int quick(int a[],int n,int beg,int end)
{
int left,right,loc;
left=beg;
right=end;
loc=beg;
while(1)
{
while((a[loc]<=a[right]) && (loc!=right))
{
right=right-1;
}
if(loc==right)
return loc;
int temp;
if(a[loc]>a[right])
{
temp=a[loc];
a[loc]=a[right];
a[right]=temp;
loc=right;


}
while((a[left]<=a[loc]) && (left!=loc))
{
left=left+1;
}
if(loc==left)
return loc;
if(a[left]>a[loc])
{
temp=a[loc];
a[loc]=a[left];
a[left]=temp;
loc=left;
}
}
}
*********output*********
Enter the elements in array
11
2
5
3
5
88
9
93
12
16

Sorted array is
2
3
5
5
9
11
12
16
88
93

using avrdude with AVR studio(for windows 10 only)

Requirements 1. arduino-1.6.5-r2-windows.exe 2. as6installer-6.0.1843.exe When I try to configure avrdude in avr studio 6 then wina...