Added insert and quick sort

This commit is contained in:
lcbcFoo 2018-04-13 19:32:07 -03:00
parent 5e5366e677
commit c4fd14d49c
3 changed files with 145 additions and 1 deletions

View file

@ -1,4 +1,4 @@
bload wcet_benchmark/prime.out
bload wcet_benchmark/insertsort.out
ep 0x40001000
run
quit

View file

@ -0,0 +1,86 @@
/* $Id: insertsort.c,v 1.2 2005/04/04 11:34:58 csg Exp $ */
/*************************************************************************/
/* */
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
/* ===================================================== */
/* Collected and Modified by S.-S. Lim */
/* sslim@archi.snu.ac.kr */
/* Real-Time Research Group */
/* Seoul National University */
/* */
/* */
/* < Features > - restrictions for our experimental environment */
/* */
/* 1. Completely structured. */
/* - There are no unconditional jumps. */
/* - There are no exit from loop bodies. */
/* (There are no 'break' or 'return' in loop bodies) */
/* 2. No 'switch' statements. */
/* 3. No 'do..while' statements. */
/* 4. Expressions are restricted. */
/* - There are no multiple expressions joined by 'or', */
/* 'and' operations. */
/* 5. No library calls. */
/* - All the functions needed are implemented in the */
/* source file. */
/* */
/* */
/*************************************************************************/
/* */
/* FILE: insertsort.c */
/* SOURCE : Public Domain Code */
/* */
/* DESCRIPTION : */
/* */
/* Insertion sort for 10 integer numbers. */
/* The integer array a[] is initialized in main function. */
/* */
/* REMARK : */
/* */
/* EXECUTION TIME : */
/* */
/* */
/*************************************************************************/
#ifdef TEST
#include "../mini_printf.h"
#include "../posix_c.h"
#else
#include <stdio.h>
#endif
unsigned int a[11];
int main()
{
int i,j, temp;
a[0] = 0; /* assume all data is positive */
a[1] = 11; a[2]=10;a[3]=9; a[4]=8; a[5]=7; a[6]=6; a[7]=5;
a[8] =4; a[9]=3; a[10]=2;
i = 2;
while(i <= 10){
j = i;
while (a[j] < a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
j--;
}
i++;
}
for(int i = 0; i < 10; i++)
if(a[i] > a[i + 1]){
printf("%d\n", 0);
return 0;
}
printf("%d\n", 1);
return 0;
}

View file

@ -0,0 +1,58 @@
#ifdef TEST
#include "../mini_printf.h"
#include "../posix_c.h"
#else
#include <stdio.h>
#endif
void swap(float* a, float* b){
float t = (*a);
(*a) = (*b);
(*b) = t;
}
int pivoting(float arr[],int b, int e){
int pivot = (b + e) / 2;
swap(&arr[pivot], &arr[e]);
pivot = b;
for(int i = b; i < e; i++){
if(arr[i] <= arr[e])
swap(&arr[i], &arr[pivot++]);
}
swap(&arr[pivot], &arr[e]);
return pivot;
}
void sort(float arr[],int b, int e){
if(b >= e)
return;
int pivot = pivoting(arr, b, e);
sort(arr, b, pivot - 1);
sort(arr, pivot + 1, e);
}
int main()
{
float arr[60] = {
5, 4, 10.3, 1.1, 5.7, 100, 231, 111, 49.5, 99,
10, 150, 222.22, 101, 77, 44, 35, 20.54, 99.99, 88.88,
114.1, 1.2, 55.4, 77.6, 29.4, 30.50, 66.4, 187.6, 215.2, 60,
25, 34, 110.3, 21.1, 15.7, 1010, 1231, 3111, 249.5, 199,
1510, 1950, 2322.22, 1031, 787, 0.44, 6.35, 250.54, 979.99, 838.88,
1184.1, 31.2, 455.4, 747.6, 292.4, 301.50, 666.4, 186.6, 235.2, 0
};
sort(arr, 0, 60-1);
for(int i = 0; i < 60-1; i++){
if(arr[i] > arr[i + 1]){
printf("%d\n", 0);
return 0;
}
}
printf("%d\n", 1);
return 0;
}