Programming with C - Direct insertion sort program

cow_theboy

Member
Dec 14, 2006
1,480
1
0
Mahavilachchiya
hi,

i wrote this program using if. Anyone can write it with while? i mean using while for sort function.

I tested follwing program n it is correct 100%. so i decided to share it with you and hope this will help those who learn c programming


#include<stdio.h>
#include<conio.h>
# define n 10
int u[n];
void input();
void sort();
void print();
void main()
{
clrscr();
input();
sort();
print();
getch();
}
void input()
{
int i ;
for(i=0 ;i<n;i++)
{
printf("\n Input data to array position %d : ",i+1);
scanf("\n %d",&u);
}
}
void sort()
{
int i,temp,j;
for(i=1 ;i<n;i++)
{
temp = u;
j=i-1;
while(j>=0)
{
if (temp<=u[j] )
{
u[j+1]=u[j];
u[j]=temp;
}

j=j-1;
}

}
}
void print()
{
int i;
for(i=0 ; i<n ;i++)
printf("\n %d",u);

}
 

madurax86

Member
Jun 29, 2006
4,385
88
0
machan meka double nested system ekata wada speed da?
ekama array eke wadima number eka hoyala tawa array ekakata dana eka
 

cow_theboy

Member
Dec 14, 2006
1,480
1
0
Mahavilachchiya
madurax86 said:
machan meka double nested system ekata wada speed da?
ekama array eke wadima number eka hoyala tawa array ekakata dana eka

ekanam danne ne machan... meka direct insertion sort. eka no ekak aran anith ewath ekka check karanawa....then adunam udata da gannawa... :lol: :lol:
 

ruc

Member
Apr 22, 2007
183
0
0
Error 1 error C3861: 'clrscr': identifier not found c:\documents and settings\sameera\my documents\visual studio 2005\projects\elakiri\elakiri\elakiri.cpp 14

Error ne...? mokadda awla..!
 

madurax86

Member
Jun 29, 2006
4,385
88
0
cow_theboy said:
ekanam danne ne machan... meka direct insertion sort. eka no ekak aran anith ewath ekka check karanawa....then adunam udata da gannawa... :lol: :lol:

array eke data shift karana podak time eka yanawa ne
man kipu krameth try karala balana e 2 benchmark parak dana :P hehe
matath sure na 2ken mokada fast kiyala man kiyana krameta aluth array ekakata numbers add wene
 

cow_theboy

Member
Dec 14, 2006
1,480
1
0
Mahavilachchiya
madurax86 said:
array eke data shift karana podak time eka yanawa ne
man kipu krameth try karala balana e 2 benchmark parak dana :P hehe
matath sure na 2ken mokada fast kiyala man kiyana krameta aluth array ekakata numbers add wene

yes machan in c there are some sorting techniques...

1. bubble sort
2. merge sort
3. Direct insertion sort
4. quick sort

dnt know what is the fatest.. cauz still learning... :lol: :lol: :lol: :lol:
 

madurax86

Member
Jun 29, 2006
4,385
88
0
cow_theboy said:
yes machan in c there are some sorting techniques...

1. bubble sort
2. merge sort
3. Direct insertion sort
4. quick sort

dnt know what is the fatest.. cauz still learning... :lol: :lol: :lol: :lol:

man theory wadiya dane na nam hitane man kiwe bubble sort wena ona anyway good work math c++ karanawa hena himin igena gane :rofl: kamali
 

patzz

Well-known member
  • Mar 2, 2008
    1,141
    603
    113
    Direct insertion sort tama fast ma oya tiken while dala liya taki machan man passe dan nam
     

    patzz

    Well-known member
  • Mar 2, 2008
    1,141
    603
    113
    NOt awesome code machan basic code ekak mulin ma tiyana awa pointers awama tamai kora wenna patan ganne me alogaritem lesi bung