SELECTION-SORT(A)
while N>0
for i <- 1 to N
if(A[i]>A[max])
do max <- A[i]
swap(A[N-1], A[max])
void selectionSort(int *A, int N){
int max, i, temp;
while(N>0){
max = 0;
/*Find max element*/
for(i=1;i<N;i++){
if(A[i]>A[max]) max = i;
}
/*swap(A[N-1], A[max])*/
temp = A[N-1];
A[N-1] = A[max];
n--;
}
}
SELECTION-SORT(A) // Cost times
while N>0 // C_1 n
for i <- 1 to N // C_2 sigma(i=0 to n, t)
if(A[i]>A[max]) // C_3 sigma(i=0 to n, t-1)
do max <- A[i] // C_4 sigma(i=0 to n, t-1)
swap(A[N-1], A[max]) // C_5 n-1
#include <stdio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable :4996)
#define max_len 10000
// #include <ctype.h>
void main (){
int dataBox[max_len];
int max,temp,index,i,n,E;
E = 0;
//file input
FILE* fin;
fin = fopen("input.txt","r");
if (fin == NULL) {
printf("Fail to read file. \n\nCheck if the \"input.txt\" file exists in the directory.\n\n");
E = 1;
}
for(i=0; i<max_len ;i++){
fscanf(fin,"%d",&dataBox[i]);
}
fclose(fin);
//Selection Sort
n = max_len;
while(n>0){
max = 0;
for(index = 1; index<n; index++){
if(dataBox[index]>dataBox[max])
max = index;
}
temp = dataBox[n-1];
dataBox[n-1] = dataBox[max];
dataBox[max] = temp;
n--;
}
//Check if there is a valid value inside the array and display it in the console.
// for(i=0; i<max_len; i++){
// printf("%d ",dataBox[i]);
// }
//
if (dataBox[0] < dataBox[max_len-1]&& E==0) {
printf("Sorting is complete.\nOpen the output file to check the results. \n\n");
}
//file output
FILE* fout;
fout = fopen("output.txt", "w+");
for(i=0; i<max_len; i++){
fprintf(fout,"%d ",dataBox[i]);
}
fclose(fout);
}
SELECTION-SORT(A)
while N>0
for i <- 1 to N
if(A[i]>A[max])
do max <- A[i]
swap(A[N-1], A[max])
void selectionSort(int *A, int N){
int max, i, temp;
while(N>0){
max = 0;
/*Find max element*/
for(i=1;i<N;i++){
if(A[i]>A[max]) max = i;
}
/*swap(A[N-1], A[max])*/
temp = A[N-1];
A[N-1] = A[max];
n--;
}
}
SELECTION-SORT(A) // Cost times
while N>0 // C_1 n
for i <- 1 to N // C_2 sigma(i=0 to n, t)
if(A[i]>A[max]) // C_3 sigma(i=0 to n, t-1)
do max <- A[i] // C_4 sigma(i=0 to n, t-1)
swap(A[N-1], A[max]) // C_5 n-1
#include <stdio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable :4996)
#define max_len 10000
// #include <ctype.h>
void main (){
int dataBox[max_len];
int max,temp,index,i,n,E;
E = 0;
//file input
FILE* fin;
fin = fopen("input.txt","r");
if (fin == NULL) {
printf("Fail to read file. \n\nCheck if the \"input.txt\" file exists in the directory.\n\n");
E = 1;
}
for(i=0; i<max_len ;i++){
fscanf(fin,"%d",&dataBox[i]);
}
fclose(fin);
//Selection Sort
n = max_len;
while(n>0){
max = 0;
for(index = 1; index<n; index++){
if(dataBox[index]>dataBox[max])
max = index;
}
temp = dataBox[n-1];
dataBox[n-1] = dataBox[max];
dataBox[max] = temp;
n--;
}
//Check if there is a valid value inside the array and display it in the console.
// for(i=0; i<max_len; i++){
// printf("%d ",dataBox[i]);
// }
//
if (dataBox[0] < dataBox[max_len-1]&& E==0) {
printf("Sorting is complete.\nOpen the output file to check the results. \n\n");
}
//file output
FILE* fout;
fout = fopen("output.txt", "w+");
for(i=0; i<max_len; i++){
fprintf(fout,"%d ",dataBox[i]);
}
fclose(fout);
}
SELECTION-SORT(A)
while N>0
for i <- 1 to N
if(A[i]>A[max])
do max <- A[i]
swap(A[N-1], A[max])
void selectionSort(int *A, int N){
int max, i, temp;
while(N>0){
max = 0;
/*Find max element*/
for(i=1;i<N;i++){
if(A[i]>A[max]) max = i;
}
/*swap(A[N-1], A[max])*/
temp = A[N-1];
A[N-1] = A[max];
n--;
}
}
SELECTION-SORT(A) // Cost times
while N>0 // C_1 n
for i <- 1 to N // C_2 sigma(i=0 to n, t)
if(A[i]>A[max]) // C_3 sigma(i=0 to n, t-1)
do max <- A[i] // C_4 sigma(i=0 to n, t-1)
swap(A[N-1], A[max]) // C_5 n-1
#include <stdio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable :4996)
#define max_len 10000
// #include <ctype.h>
void main (){
int dataBox[max_len];
int max,temp,index,i,n,E;
E = 0;
//file input
FILE* fin;
fin = fopen("input.txt","r");
if (fin == NULL) {
printf("Fail to read file. \n\nCheck if the \"input.txt\" file exists in the directory.\n\n");
E = 1;
}
for(i=0; i<max_len ;i++){
fscanf(fin,"%d",&dataBox[i]);
}
fclose(fin);
//Selection Sort
n = max_len;
while(n>0){
max = 0;
for(index = 1; index<n; index++){
if(dataBox[index]>dataBox[max])
max = index;
}
temp = dataBox[n-1];
dataBox[n-1] = dataBox[max];
dataBox[max] = temp;
n--;
}
//Check if there is a valid value inside the array and display it in the console.
// for(i=0; i<max_len; i++){
// printf("%d ",dataBox[i]);
// }
//
if (dataBox[0] < dataBox[max_len-1]&& E==0) {
printf("Sorting is complete.\nOpen the output file to check the results. \n\n");
}
//file output
FILE* fout;
fout = fopen("output.txt", "w+");
for(i=0; i<max_len; i++){
fprintf(fout,"%d ",dataBox[i]);
}
fclose(fout);
}
SELECTION-SORT(A)
while N>0
for i <- 1 to N
if(A[i]>A[max])
do max <- A[i]
swap(A[N-1], A[max])
void selectionSort(int *A, int N){
int max, i, temp;
while(N>0){
max = 0;
/*Find max element*/
for(i=1;i<N;i++){
if(A[i]>A[max]) max = i;
}
/*swap(A[N-1], A[max])*/
temp = A[N-1];
A[N-1] = A[max];
n--;
}
}
SELECTION-SORT(A) // Cost times
while N>0 // C_1 n
for i <- 1 to N // C_2 sigma(i=0 to n, t)
if(A[i]>A[max]) // C_3 sigma(i=0 to n, t-1)
do max <- A[i] // C_4 sigma(i=0 to n, t-1)
swap(A[N-1], A[max]) // C_5 n-1
#include <stdio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable :4996)
#define max_len 10000
// #include <ctype.h>
void main (){
int dataBox[max_len];
int max,temp,index,i,n,E;
E = 0;
//file input
FILE* fin;
fin = fopen("input.txt","r");
if (fin == NULL) {
printf("Fail to read file. \n\nCheck if the \"input.txt\" file exists in the directory.\n\n");
E = 1;
}
for(i=0; i<max_len ;i++){
fscanf(fin,"%d",&dataBox[i]);
}
fclose(fin);
//Selection Sort
n = max_len;
while(n>0){
max = 0;
for(index = 1; index<n; index++){
if(dataBox[index]>dataBox[max])
max = index;
}
temp = dataBox[n-1];
dataBox[n-1] = dataBox[max];
dataBox[max] = temp;
n--;
}
//Check if there is a valid value inside the array and display it in the console.
// for(i=0; i<max_len; i++){
// printf("%d ",dataBox[i]);
// }
//
if (dataBox[0] < dataBox[max_len-1]&& E==0) {
printf("Sorting is complete.\nOpen the output file to check the results. \n\n");
}
//file output
FILE* fout;
fout = fopen("output.txt", "w+");
for(i=0; i<max_len; i++){
fprintf(fout,"%d ",dataBox[i]);
}
fclose(fout);
}
SELECTION-SORT(A)
while N>0
for i <- 1 to N
if(A[i]>A[max])
do max <- A[i]
swap(A[N-1], A[max])
void selectionSort(int *A, int N){
int max, i, temp;
while(N>0){
max = 0;
/*Find max element*/
for(i=1;i<N;i++){
if(A[i]>A[max]) max = i;
}
/*swap(A[N-1], A[max])*/
temp = A[N-1];
A[N-1] = A[max];
n--;
}
}
SELECTION-SORT(A) // Cost times
while N>0 // C_1 n
for i <- 1 to N // C_2 sigma(i=0 to n, t)
if(A[i]>A[max]) // C_3 sigma(i=0 to n, t-1)
do max <- A[i] // C_4 sigma(i=0 to n, t-1)
swap(A[N-1], A[max]) // C_5 n-1
#include <stdio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable :4996)
#define max_len 10000
// #include <ctype.h>
void main (){
int dataBox[max_len];
int max,temp,index,i,n,E;
E = 0;
//file input
FILE* fin;
fin = fopen("input.txt","r");
if (fin == NULL) {
printf("Fail to read file. \n\nCheck if the \"input.txt\" file exists in the directory.\n\n");
E = 1;
}
for(i=0; i<max_len ;i++){
fscanf(fin,"%d",&dataBox[i]);
}
fclose(fin);
//Selection Sort
n = max_len;
while(n>0){
max = 0;
for(index = 1; index<n; index++){
if(dataBox[index]>dataBox[max])
max = index;
}
temp = dataBox[n-1];
dataBox[n-1] = dataBox[max];
dataBox[max] = temp;
n--;
}
//Check if there is a valid value inside the array and display it in the console.
// for(i=0; i<max_len; i++){
// printf("%d ",dataBox[i]);
// }
//
if (dataBox[0] < dataBox[max_len-1]&& E==0) {
printf("Sorting is complete.\nOpen the output file to check the results. \n\n");
}
//file output
FILE* fout;
fout = fopen("output.txt", "w+");
for(i=0; i<max_len; i++){
fprintf(fout,"%d ",dataBox[i]);
}
fclose(fout);
}
SELECTION-SORT(A)
while N>0
for i <- 1 to N
if(A[i]>A[max])
do max <- A[i]
swap(A[N-1], A[max])
void selectionSort(int *A, int N){
int max, i, temp;
while(N>0){
max = 0;
/*Find max element*/
for(i=1;i<N;i++){
if(A[i]>A[max]) max = i;
}
/*swap(A[N-1], A[max])*/
temp = A[N-1];
A[N-1] = A[max];
n--;
}
}
SELECTION-SORT(A) // Cost times
while N>0 // C_1 n
for i <- 1 to N // C_2 sigma(i=0 to n, t)
if(A[i]>A[max]) // C_3 sigma(i=0 to n, t-1)
do max <- A[i] // C_4 sigma(i=0 to n, t-1)
swap(A[N-1], A[max]) // C_5 n-1
#include <stdio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable :4996)
#define max_len 10000
// #include <ctype.h>
void main (){
int dataBox[max_len];
int max,temp,index,i,n,E;
E = 0;
//file input
FILE* fin;
fin = fopen("input.txt","r");
if (fin == NULL) {
printf("Fail to read file. \n\nCheck if the \"input.txt\" file exists in the directory.\n\n");
E = 1;
}
for(i=0; i<max_len ;i++){
fscanf(fin,"%d",&dataBox[i]);
}
fclose(fin);
//Selection Sort
n = max_len;
while(n>0){
max = 0;
for(index = 1; index<n; index++){
if(dataBox[index]>dataBox[max])
max = index;
}
temp = dataBox[n-1];
dataBox[n-1] = dataBox[max];
dataBox[max] = temp;
n--;
}
//Check if there is a valid value inside the array and display it in the console.
// for(i=0; i<max_len; i++){
// printf("%d ",dataBox[i]);
// }
//
if (dataBox[0] < dataBox[max_len-1]&& E==0) {
printf("Sorting is complete.\nOpen the output file to check the results. \n\n");
}
//file output
FILE* fout;
fout = fopen("output.txt", "w+");
for(i=0; i<max_len; i++){
fprintf(fout,"%d ",dataBox[i]);
}
fclose(fout);
}