in programul dat functia swich e ignorata si respetiv programul nu functioneaza=(
cum pot sa il repar????????
#include
#include
void bub_sort(int* t,int t_size) {
int temp;
for (int k = 0; k < t_size; k++)
for (int i = 0; i < t_size - k - 1; i++) {
if (t[i] > t[i + 1]) {
temp = t[i];
t[i] = t[i + 1];
t[i + 1] = temp;
}
}
}
void sh_sort(int* t,int t_size) {
int swap;
swap = 1; //true
int temp;
while (swap){
swap = 0;//false
for (int i = 0; i < t_size - 1; i++) {
if (t[i] > t[i + 1]) {
temp = t[i];
t[i] = t[i + 1];
t[i + 1] = temp;
swap = 1;//true
}
}
if (!swap){
break;
}
swap = 0;//false
for (int i = t_size - 2; i >= 0; i--) {
if (t[i] > t[i + 1]) {
temp = t[i];
t[i] = t[i + 1];
t[i + 1] = temp;
swap = 1; //true
}
}
}
}
int main( void ) {
int op = 0;
int i, n;
int *tab;
printf("Introdu n : ");
scanf("%d",&n);
tab=malloc(n*sizeof(int));
for (int i = 0; i < n; i++){
scanf("%d",&tab[i]); //creearea tabloului
}
while ( op != 3 ){
puts("Select" );
puts("1 - sh");
puts("2 - bub");
puts("3 - EXIT");
scanf("%d",op);
switch (op) {
case 1:
bub_sort(tab,n);
for (int i = 0; i < n; i++){
printf("%d ",tab[i]);
}
break;
case 2:
sh_sort(tab,n);
for (int i = 0; i < n; i++){
printf("%d ",tab[i]);
}
break;
}
}
printf("Program finished...\n");
return 0;
}