The teacher told us to separate our bubblesort code into functions.
The first one is input, then processing, then output.
The problem is I have no idea how to communicate so many values between functions, i know that i can return one value, but that isn't enough. I also know that it can be done using pointers (the teacher suggested this.)
The problem is my understanding of pointers isn't entirely clear. Could someone explain them in the context of my homework?
Don't mind what i did there, I was just experimenting. Otherwise the bubblesort itself and everything should work, i just can't get the damned values from one function to another...
All help is greatly appreciated
Code:
#include<stdio.h>
int n,vrd=0,loe=0; float array[];
void sisestus(int *n,float array[] )
{
printf("\nPlease enter the number of elements :");
scanf("%d", &n);
int i=0;
for(i=0;i<n;i++)
{
printf("sisesta element nr ");
printf("%d",i+1);
printf(" \n");
scanf("%f",&array[i]);}
}
void mullsort(int *n, int *loe, int *vrd,float array[] )
{
int temp;
int i,j;
for(i = 0; i < n-1; i++)
for(j = i + 1; j < n; j++)
{ vrd++;
if(array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
loe=loe+1;
}
}
}
void v2ljastus(int *n,int *loe,int *vrd,float array[])
{
int i=0;
for(i=0;i<n;i++)
printf("%f",array[i]);
printf("The number of switches was \n");
printf("%d",loe);
printf("\nThe number of comparisons was : %d", vrd);
}
int main()
{
sisestus(&n,array);
mullsort(&n,&loe,&vrd,array);
v2ljastus(&n,&loe,&vrd,array);
return 0;
}