What is simple way to sort?
thank you
CodePudding user response:
I write early bubble sort of
# include & lt; Stdio. H>
# define ARRAYNUM 5
Int main (int arg c, char * argv [])
{
An int array [ARRAYNUM]={5, 1, 9, 3, 15};
Int I=0, j=0;
Int TMP=0;
For (I=0; I & lt; ARRAYNUM; I++)
{
For (j=0; J & lt; I; J++)
{
If (array [j] & gt; Array [j + 1])
{
TMP=array [j];
Array [j]=array [j + 1);
Array [j + 1)=TMP;
}
}
}
Printf (" array after sort [1 - & gt; n] : \ n ");
For (I=0; I & lt; ARRAYNUM; I++)
{
Printf (" % d ", array [I]);
}
printf("\n");
For (I=0; I & lt; ARRAYNUM; I++)
{
For (j=ARRAYNUM - 1; J & gt; I; J -)
{
If (array [j] & gt; Array [1])
{
TMP=array [j];
Array [j]=array [j - 1);
Array [] j - 1=TMP;
}
}
}
Printf (" array after sort [1] n - & gt; : \ n ");
For (I=0; I & lt; ARRAYNUM; I++)
{
Printf (" % d ", array [I]);
}
printf("\n");
return 0;
}
CodePudding user response:
//simple mercifully sort is adequate for small number of tabs
Void CRulerBar: : SortTabs ()
{
Int I, j, nPos.
for (i=0; I{
for (j=i+1; J & lt; MAX_TAB_STOPS; J++)
{
If (m_pTabItems [j] GetHorzPosTwips () & lt; M_pTabItems [I] GetHorzPosTwips ())
{
NPos=m_pTabItems [j] GetHorzPosTwips ();
M_pTabItems [j] SetHorzPosTwips (m_pTabItems [I] GetHorzPosTwips ());
M_pTabItems [I] SetHorzPosTwips (nPos);
}
}
}
}
CodePudding user response:
Vectorv;
V.r eserve (10);
for(int i=0; I<10; I++)
Valerie plame ush_back (rand () % 20);
Sort (what exactly do v.begin (), v.e nd ());
CodePudding user response:
10 elements, what method is okVoid the sort (int * pA, int n)
{
Int Temp, Temp1;
For (int I=0, i
Temp=pA [I];
For (int j=I + 1; J
If (Temp> PA [j])
{
Temp1=pA [j];
PA [j]=Temp;
Temp=Temp1;
}
}
PA [I]=Temp;
}
}