-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtp0.c
56 lines (49 loc) · 1.21 KB
/
tp0.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "tp0.h"
#include <stdio.h>
/* *****************************************************************
* FUNCIONES A COMPLETAR *
* (ver en tp0.h la documentación de cada función) *
* *****************************************************************/
void swap (int *x, int *y) {
int aux = *x;
*x = *y;
*y = aux;
}
int maximo(int vector[], int n) {
int pos = 0;
if(n == 0){
return -1;
}
for(int i = 0; i < n; i++){
if(vector[i] > vector[pos]){
pos = i;
}
}
return pos;
}
int comparar(int vector1[], int n1, int vector2[], int n2) {
for(int i = 0; i < n1 && i < n2; i ++){
if(vector1[i]< vector2[i]){
return -1;
}else{
if(vector1[i] > vector2[i]){
return 1;
}
}
}
if(n1 < n2){
return -1;
}
if(n1 > n2){
return 1;
}
return 0;
}
void seleccion(int vector[], int n) {
int i;
for(i = 0; i < n; i++){
int cotaMayor = n - i;
int maxRestante = maximo(vector, cotaMayor);
swap(&vector[maxRestante], &vector[cotaMayor - 1]);
}
}