Skip to content
Snippets Groups Projects
Commit 36e1d4bd authored by abivarma.kandiah's avatar abivarma.kandiah
Browse files

Ex 7

parent 56fd67cf
No related branches found
No related tags found
No related merge requests found
......@@ -72,5 +72,12 @@ void CyclicSwapTab(int64_t *tab, int64_t tab_len, int64_t swap_times);
*/
int64_t FindLowIndex(int64_t *tab, int64_t tab_len);
/**
@brief Tri par instertion Decroissant
@param [int] *tab, input table
@param [int] tab_len, table lenght
@return [void]
*/
void TriInsertionDescent(int64_t *tab, int64_t tab_len);
#endif
\ No newline at end of file
......@@ -42,6 +42,11 @@ int main()
Swap(&tab[FindLowIndex(tab, size)], &tab[size-1]);
PrintTableau(tab, size);
//7.
TriInsertionDescent(tab, size);
PrintTableau(tab, size);
//8.
//Free the Malloc
free(tab);
......
......@@ -127,3 +127,23 @@ int64_t FindLowIndex(int64_t *tab, int64_t tab_len)
return low_index;
}
/**
@brief Tri par instertion Decroissant
@param [int] *tab, input table
@param [int] tab_len, table lenght
@return [void]
*/
void TriInsertionDescent(int64_t *tab, int64_t tab_len)
{
for (int64_t i = tab_len - 2; i >= 0; i--)
{
int64_t tmp = tab[i];
int64_t pos = i;
while (pos < tab_len - 1 && tab[pos + 1] > tmp)
{
tab[pos] = tab[pos + 1];
pos = pos + 1;
}
tab[pos] = tmp;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment