Created
October 13, 2016 00:21
-
-
Save olegon/6e2f920c8d86f672c871c21928f63111 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void insertion_ints(int v[], int n); | |
void insertion_chars(char v[], int n); | |
void insertion_strings(char* v[], int n); | |
int main (void) { | |
int i; | |
int ints[] = { 7, 5, 9, 3, 1 }; | |
insertion_ints(ints, 5); | |
printf("Inteiros: "); | |
for (i = 0; i < 5; i++) { | |
printf("%d ", ints[i]); | |
} | |
printf("\n"); | |
char chars[] = "david"; | |
insertion_chars(chars, 5); | |
printf("Caracteres: "); | |
for (i = 0; i < 5; i++) { | |
printf("%c", chars[i]); | |
} | |
printf("\n"); | |
char* strings[] = { "david", "leandro", "alexis", "fernando", "debora" }; | |
insertion_strings(strings, 5); | |
printf("Strings: "); | |
for (i = 0; i < 5; i++) { | |
printf("%s ", strings[i]); | |
} | |
printf("\n"); | |
return 0; | |
} | |
void insertion_ints(int v[], int n) { | |
int i, j; | |
for (i = 1; i < n; i++) { | |
for (j = i; j > 0 && v[j] < v[j - 1]; j--) { | |
int copy = v[j - 1]; | |
v[j - 1] = v[j]; | |
v[j] = copy; | |
} | |
} | |
} | |
void insertion_chars(char v[], int n) { | |
int i, j; | |
for (i = 1; i < n; i++) { | |
for (j = i; j > 0 && v[j] < v[j - 1]; j--) { | |
char copy = v[j - 1]; | |
v[j - 1] = v[j]; | |
v[j] = copy; | |
} | |
} | |
} | |
void insertion_strings(char* v[], int n) { | |
int i, j; | |
for (i = 1; i < n; i++) { | |
for (j = i; j > 0 && strcmp(v[j], v[j - 1]) < 0; j--) { | |
char* copy = v[j - 1]; | |
v[j - 1] = v[j]; | |
v[j] = copy; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment