Skip to content

Commit a6a5c77

Browse files
author
Kendrick Ledet
committed
PROPERLY separated algorithm into function
Passes in first address of sequence array as pointer.
1 parent 9b0f713 commit a6a5c77

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

39 Bytes
Binary file not shown.

Insertion_Sort/C/kennyledet/insertion_sort.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
void print_sequence(int [], int);
11+
void insertion_sort(int*, int);
1112

1213
int main(int argc, char *argv[])
1314
{
@@ -17,7 +18,16 @@ int main(int argc, char *argv[])
1718
printf("Sorting %d values in sequence ", sequence_length);
1819
print_sequence(sequence, sequence_length);
1920

20-
/* Insertion Sort */
21+
insertion_sort(sequence, sequence_length);
22+
23+
printf("Done sorting. Result ");
24+
print_sequence(sequence, sequence_length);
25+
26+
return 0;
27+
}
28+
29+
void insertion_sort(int *sequence, int sequence_length)
30+
{
2131
int marker, key_index, key;
2232

2333
for (key_index = 1; key_index < sequence_length; key_index++) { // traverse sequence, start at 2nd index
@@ -30,11 +40,6 @@ int main(int argc, char *argv[])
3040
}
3141
sequence[marker+1] = key; // replace key
3242
}
33-
34-
printf("Done sorting into result sequence ");
35-
print_sequence(sequence, sequence_length);
36-
37-
return 0;
3843
}
3944

4045
void print_sequence(int seq[], int seq_len)

0 commit comments

Comments
 (0)