למי שיודע להעריך.
.
א. מיון בחירה (by Selection) - selectionSort.cpp>>:
#include <stdio.h<
#include <conio.h<
#include <stdlib.h<
#define N 6
void selectionSort(int [], int);
void main()
}
int arr[N] = {5,9,1,2,8,10}; //makes array
selectionSort(arr,N); //calls selectionSort function
for (int i=0;i<N;i++) //prints the array
printf("%4d",arr[i]);
puts("\n”);
}
void selectionSort(int arr[], int size(
}
int i, j, min,temp;
for (i=0;i<size-1;i++)
}
min=i;
for(j=i+1;j<N;j++);
}
if (arr[j] < arr[min])
}
min=j;
}
}
temp = arr[i]; //makes a swap
arr[i] = arr[min];
arr[min] = temp;
}
}
ב. מיון הכנסה משופר (by Insertion) - <insertionSort.cpp>:
#include <stdio.h>
#include <conio.h<
#include <stdlib.h<
#define N 6
void insertionSort(int []);
void main()
}
int arr[N] = {5,9,1,2,8,10}; //makes array
insertionSort(arr); //calls insertionSort function
for (int i=0;i<N;i++) //prints the array
printf("%4d",arr[i]);
puts("\n”);
}
void insertionSort(int arr[])
}
int i, j, value;
for (i=0;i<N-1;i++)
}
value =arr[i];
j = i-1;
while ((j>=0) && (arr[j] > value))
}
arr[j+1] = arr[j];
j = j-1;
}
arr[j+1] = value;
}
}
ג. מיוני החלפה (shellSort, ShakerSort, bubbleSort)
<shellSort.cpp>:
#include <stdio.h<
#include <conio.h<
#include <stdlib.h<
#define N 6
void shellSort(int [], int);
void main()
}
int arr[N] = {5,9,1,2,8,10}; //makes array
shellSort (arr); //calls insertionSort function
for (int i=0;i<N;i++) //prints the array
printf("%4d",arr[i]);
puts("\n”);
}
void shellSort(int arr[], int N)
}
int i, j, size, temp;
size = N/2; //half array
while (size > 0)
{
for (i=size;i<N;i++)
}
j=i
temp = arr[i];
while ((j>=size) && (arr[j-size] > temp))
}
arr[j] = arr[j-size];
j = j -size;
} //while
arr[j] = temp;
}
}
}
<shakerSort.cpp>:
#include <stdio.h<
#include <conio.h<
#include <stdlib.h<
#define N 6
void shakerSort(int [], int);
void main()
}
int arr[N] = {5,9,1,2,8,10}; //makes array
shakerSort (arr); //calls shakerSort function
for (int i=0;i<N;i++) //prints the array
printf("%4d",arr[i]);
puts("\n”);
}
void shakerSort(int arr[], int N)
}
int i, bottom=0, top=N-1,temp;
bool swapped=true;
while (swapped == true(
}
swapped = false;
for (i=bottom;i<top;i++)
}
if (arr[i] > arr[i+1])
}
temp = arr[i]; //makes a swap
arr[i] = arr[i+1];
arr[i+1] = temp;
swapped = true; //was a swapped
}
}
top--;
for (i=top;i>borrom;i--)
}
if (arr[i] < arr[i-1])
}
temp = arr[i]; //makes a swap
arr[i] = arr[i-1]:
arr[i-1] = temp;
swapped = true; //was a swapped
}
}
bottom++;
}
}
<bubbleSort.cpp>:
#include <stdio.h<
#include <conio.h<
#include <stdlib.h<
#define N 6
void bubbleSort(int []);
void main()
}
int arr[N] = {5,9,1,2,8,10}; //makes array
bubbleSort (arr); //calls bubbleSort function
for (int i=0;i<N;i++) //prints the array
printf("%4d",arr[i]);
puts("\n”);
}
void bubbleSort(int arr[])
}
int i, j, temp;
for (i=1;i<N;i++)
}
for (j=N;j>i+1;j--)
}
if (arr[j] < arr[j-1])
}
temp = arr[j]; //makes a swap
arr[j] = arr[j-1]j
arr[j-1] = temp;
}
}
}
}



ציטוט ההודעה