Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
Group name : cenghks
Authors:
Mustafa Erdem Kırgıl-130144035
Elif Nur Haner -130144028
Merve Hande Sarıkaya-130144047
Date:15.12.2013
*/
#include<getopt.h>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include <stdio.h>
#include<cstdio>
#include<chrono>
#include <cmath>
#include <stdlib.h>
void swap1(int *x,int *y)
{
long temp=*x;
*x=*y;
temp=*y;
}
void merge_sort(int* arrayname, int ilast, int ilast2) {
int i = 0;
int j = ilast;
int k = 0;
int* itmp = new int[ilast2];
while (i < ilast && j < ilast2) {
if (arrayname[i] < arrayname[j]) {
itmp[k] = arrayname[i];
++i;
} else {
itmp[k] = arrayname[j];
++j;
}
++k;
}
while (i < ilast) {
itmp[k] = arrayname[i];
++i;
++k;
}
while (j < ilast2) {
itmp[k] = arrayname[j];
++j;
++k;
}
for (int ivalue = 0; ivalue < ilast2; ++ivalue) {
arrayname[ivalue] = itmp[ivalue];
}
delete [] itmp;
}
void quick_sort(int arrayy[], int left, int right) {
int i = left, j = right;
int tmp;
int middle = arrayy[(left + right) / 2];
/* partition */
while (i <= j) {
while (arrayy[i] < middle)
i++;
while (arrayy[j] > middle)
j--;
if (i <= j) {
tmp = arrayy[i];
arrayy[i] = arrayy[j];
arrayy[j] = tmp;
i++;
j--;
}
};
/* recursion */
if (left < j)
quick_sort(arrayy, left, j);
if (i < right)
quick_sort(arrayy, i, right);
}
int get_max(int arrayy[], int n)
{
int kv = arrayy[0];
for (int i = 1; i < n; i++)
if (arrayy[i] > kv)
kv = arrayy[i];
return kv;
}
// A function to do counting sort of arr[] according to
// the digit represented by exp.
void count_sort(int arrayy[], int n, int ex)
{
int output[n]; // output array
int i, count[10] = {0};
// Store count of occurrences in count[]
for (i = 0; i < n; i++)
count[ (arrayy[i]/ex)%10 ]++;
// Change count[i] so that count[i] now contains actual
// position of this digit in output[]
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
// Build the output array
for (i = n - 1; i >= 0; i--)
{
output[count[ (arrayy[i]/ex)%10 ] - 1] = arrayy[i];
count[ (arrayy[i]/ex)%10 ]--;
}
// Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to current digit
for (i = 0; i < n; i++)
arrayy[i] = output[i];
}
// The main function to that sorts arr[] of size n using
// Radix Sort
void radix_sort(int arrayy[], int n)
{
// Find the maximum number to know number of digits
int m = get_max(arrayy, n);
// Do counting sort for every digit. Note that instead
// of passing digit number, exp is passed. exp is 10^i
// where i is current digit number
for (int ex = 1; m/ex > 0; ex *= 10)
count_sort(arrayy, n, ex);
}
void insertion_sort(int arrayy[], int distinct) {
int i, j ,tmp;
for (i = 1; i < distinct; i++) {
j = i;
while (j > 0 && arrayy[j - 1] > arrayy[j]) {
tmp = arrayy[j];
arrayy[j] = arrayy[j - 1];
arrayy[j - 1] = tmp;
j--;
}
}
}
void selection_sort(int arrayy[], int n) {
int i, j, mindex, tmp;
for (i = 0; i < n - 1; i++) {
mindex = i;
for (j = i + 1; j < n; j++)
if (arrayy[j] < arrayy[mindex])
mindex = j;
if (mindex != i) {
swap1(&arrayy[i] , &arrayy[mindex]);
}
}
}
void bubbleSort(int array2[], int element)
{
int temp;
int i, j;
for (i=1; i<element; i++)
{
for (j=0; j<element-i; j++)
{
if(array2[j] > array2[j+1])
{
swap1(&array2[i],&array2[i+1]);
}
}
}
}
int main(int argc,char *argv[]){
int b;
while ((b = getopt(argc, argv,"s:o:")) != -1){
}
int i=atoi(argv[2]) ;
int *array1 =new int[i];
const char* abc = argv[4] ;
char* arraycns=const_cast<char*>(abc);
for(int j=0;j<i;j++){
array1[j]=rand()%50;
}
if(*arraycns=='A'){
for(int i1=0; i1<=i-1; i1++)
{
for(int j1=i1+1; j1<=i1; j1++)
{
if(array1[i1]>array1[j1])
{
swap1(&i1,&j1);
}
}
}
}
if(*arraycns=='D'){
for(int i1=0; i1<=i-1; i1++)
{
for(int j1=i1+1; j1<=i1; j1++)
{
if(array1[i1]<array1[j1])
{
swap1(&i1,&j1);
}
}
}
}
if(*arraycns=='R'){
for(int j1=0;j1<i;j1++){
array1[j1]=rand()%50;
}
}
if(*arraycns=='R'||*arraycns=='D'||*arraycns=='A'){
int *array2=new int[i];
for(int k=0;k<i;k++){
array2[k]=array1[k];
}
int *array3=new int[i];
for (int l=0;l<i;l++){
array3[l]=array1[l];
}
int *array4=new int[i];
for(int m=0;m<i;m++){
array4[m]=array1[m];
}
int *array5=new int[i];
for(int n=0;n<i;n++){
array5[n]=array1[n];
}
int *array6=new int[i];
for(int o=0;o<i;o++){
array6[o]=array1[o];
}
int *array7=new int[i];
for(int p=0;p<i;p++){
array7[p]=array1[p];
}
double duration;
auto start = std::clock();
selection_sort(array3,i);
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
printf("selectionSort: %.2f nanoseconds .n",((double)(duration))*1000*1000000) ;
double duration1;
start = std::clock();
bubbleSort(array2,i);
duration1 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
printf("bubbleSort: %.2f nanoseconds .n",((double)(duration1))*1000*1000000) ;
double duration2;
start = std::clock();
insertion_sort(array4,i);
duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
printf("insertion: %.2f nanoseconds .n",((double)(duration2))*1000*1000000) ;
double duration3;
start = std::clock();
radix_sort(array5,i);
duration3 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
printf("radixSort: %.2f nanoseconds .n",((double)(duration3))*1000*1000000) ;
double duration4;
start = std::clock();
quick_sort(array6,array6[0],i);
duration4 = (double)( std::clock() - start ) / (double) CLOCKS_PER_SEC;
printf("quicksort: %.2f nanoseconds .n",((double)(duration4))*1000*1000000) ;
double duration5;
start = std::clock();
merge_sort(array7,array7[0],i);
duration5 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
printf("Merge: %.2f nanoseconds .n",((double)(duration5))*1000*1000000) ;
}
else{
printf("Invalid argument.");
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team