Мне нужна программа, чтобы я мог сортировать по пузырькам динамический массив, заполненный случайными числами от 1 до 100, используя следующие функции: Функция сортировки по пузырькам.У меня есть этот код, но я не знаю, почему функция Bubble sort не работает, пожалуйста, помогите мне.Вот мой код:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define TAM 100
void fill(int vector[]){
int i;
srand (time(NULL));
for(i=0; i<=TAM; i++){
vector[i]= rand()%100+1;
}
}
void swap(int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;
}
void bubble (int vector[], int n){
int c,d,t;
for (c=0; c<n-1; c++){
for (d=0 ;d<n-c-1; d++){
if (vector[d] > vector[d+1]) {
swap(&vector[d+1], &vector[d+1]);
/* Swapping */
/*t=vector[d];
vector[d]=vector[d+1];
vector[d+1]=t;*/
}
}}}
/*void print (){
}*/
int main(void){
//int vector[];
int *vector;
vector = (int*)malloc(sizeof(int)*TAM);
if (vector==NULL){
perror("Problemas reservando memoria");
exit (1);
}
fill(vector);
bubble(vector, 100);
printf("%i", vector);
free (vector);
return 0;
}