C
coderNabil
Guest
Selection algorithm i am stuck.
1. for (i = 0; i < size - 1; i++)
2. for (j = i + 1; j < size; j++)
Can you please explain. the line number 1 and 2?
what will be j value
j = i + 1
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
void main()
{
int a[SIZE] = {8,5,2,3,1,6,9,4,0,7};
void selection_sort(int* a,const int size)
{
int i, j, min;
for (i = 0; i < size - 1; i++)
{
min = i;
for (j = i + 1; j < size; j++)
{
if (a[j] < a[min])
{
min = j;
}
}
swap(&a, &a[min]);
}
}
/*
display array content
*/
Continue reading...
1. for (i = 0; i < size - 1; i++)
2. for (j = i + 1; j < size; j++)
Can you please explain. the line number 1 and 2?
what will be j value
j = i + 1
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
void main()
{
int a[SIZE] = {8,5,2,3,1,6,9,4,0,7};
void selection_sort(int* a,const int size)
{
int i, j, min;
for (i = 0; i < size - 1; i++)
{
min = i;
for (j = i + 1; j < size; j++)
{
if (a[j] < a[min])
{
min = j;
}
}
swap(&a, &a[min]);
}
}
/*
display array content
*/
Continue reading...