-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubbleSequencial.c
61 lines (57 loc) · 1.22 KB
/
bubbleSequencial.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
57
58
59
60
61
#include "bubbleSequencial.h"
int* aleatorio1(){
int *vetor = (int*)malloc(MAX1*sizeof(int));
int j, aux;
for(int i = 0; i<MAX1;i++){
vetor[i]=i;
}
for(int i = MAX1-1; i>=0; i--){
j = (rand() % (i+1));
aux = vetor[i];
vetor[i] = vetor[j];
vetor[j] = aux;
}
return vetor;
}
void CreateRandomTXT1() {
int* vetorint = aleatorio1();
FILE *txt;
txt = fopen("randomList.txt", "w");
for (int i = 0; i < MAX1; i ++) {
fprintf(txt, "%i\n", vetorint[i]);
}
fclose(txt);
}
void Bubble1(int *ListaSeq) {
bool verificador = true;
while(verificador == true){
verificador = false;
for (int j = 0; j < (MAX1 - 1); j ++) {
if(ListaSeq[j] > ListaSeq[j + 1]) {
int AUX = ListaSeq[j + 1];
ListaSeq[j + 1] = ListaSeq[j];
ListaSeq[j] = AUX;
verificador = true;
}
}
}
}
void TXTtoLIST1(int *ListaSeq){
int x = 0, cont = 0;
FILE *txt;
txt = fopen("randomList.txt", "r");
while(fscanf(txt, "%i", &x) != EOF) {
ListaSeq[cont] = x;
cont ++;
}
fclose(txt);
}
void LISTtoTXT1(int *ListaSeq) {
int i;
FILE *txt;
txt = fopen("bubble.txt", "w");
for (i = 0; i < MAX1; i ++) {
fprintf(txt, "%i\n", ListaSeq[i]);
}
fclose(txt);
}