User Tools

Site Tools


user:bkenne11:portfolio:bogosort

Project: Bogo Sort

A project for Data Structures by Brandon Kennedy during the Fall 2011 Semester.

This project was begun on 12-15-2011 and is anticipated to take 2 hours.

Objectives

The purpose of this project is to straight up have some fun. I am going to implement a bogosort program that will sort integers from lowest to highest value and output them.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • wikipedia on bogosorts.

Background

The background to this project is to have some fun on my last project. I need another sort so i am implementing a bogo sort program.

Attributes

State and justify the attributes you'd like to receive upon successful approval and completion of this project.

  • attribute1: sorts → this is a bogo sorting implementation.

Code

1
//bogo.c, a bogosort implementation for Data Structures
//By Brandon Kennedy
//compile: gcc -o bogo bogo.c
//run ./bogo
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
        int size=10;
        int tmp=0,i,one=0,two=0;
        int value[size];
        char sort = 'n';
        for(i=0;i<size;i++)
        {
                printf("enter a value for slot %d: ", i);
                scanf("%d", &value[i]);
        }
        while(sort == 'n')
        {
                sort = 'y';
                one = (rand() % size);
                two = (rand() % size);
                tmp = value[one];
                value[one] = value[two];
                value[two] = tmp;
                for(i=0;i<size;i++)
                {
                        if(value[i] > value[i+1])
                                sort = 'n';
                }
        }
        for(i=0;i<size;i++)
                printf(". %d ", value[i]);
        return 0;
}

Execution

Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:

. 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 90 lab46:~/src/DataS$ ./bogo
enter a value for slot 0: 1
enter a value for slot 1: 3
enter a value for slot 2: 2
enter a value for slot 3: 5
enter a value for slot 4: 4
enter a value for slot 5: 7
enter a value for slot 6: 6
enter a value for slot 7: 9
enter a value for slot 8: 8
enter a value for slot 9: 0
. 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 lab46:~/src/DataS$ ./bogo
enter a value for slot 0: 1
enter a value for slot 1: 2
enter a value for slot 2: 4
enter a value for slot 3: 3
enter a value for slot 4: 7
enter a value for slot 5: 5
enter a value for slot 6: 8
enter a value for slot 7: 9
enter a value for slot 8: 6
enter a value for slot 9: 10
. 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10 lab46:~/src/DataS$ ./bogo
enter a value for slot 0: 12
enter a value for slot 1: 345
enter a value for slot 2: 67
enter a value for slot 3: 945
enter a value for slot 4: 35
enter a value for slot 5: 65
enter a value for slot 6: 4
enter a value for slot 7: 32
enter a value for slot 8: 76
enter a value for slot 9: 54
. 4 . 12 . 32 . 35 . 54 . 65 . 67 . 76 . 345 . 945 lab46:~/src/DataS$ nano bogo.c
lab46:~/src/DataS$

Reflection

Bogosorts are crap, they really are… it could take who knows how long to sort a bag of numbers by shaking it and dumping it on the floor… I have deffinitely seen the light on how 0(n) calculations are important.

References

In performing this project, the following resources were referenced:

  • wiki on bogosorts to get the flow of things :p
user/bkenne11/portfolio/bogosort.txt · Last modified: 2011/12/15 22:23 by bkenne11