Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <float.h>
- /* Insertion sort
- * Learn debugging
- * Work on implementation of shit
- */
- void input(int * array, int size, int *num_inuts);
- void findingsmaller(int *array, int num_inputs);
- void goleft(int *array, int a, int b);
- int main(void)
- {
- int array[200];
- int size = sizeof(array)/sizeof(int);
- int num_inputs = 0;
- int i;
- input(array, size, &num_inputs);
- findingsmaller(array, num_inputs);
- for (i=0; i== num_inputs-1; i++) {
- printf("%d ", array[i]);
- }
- printf("\n");
- return (EXIT_SUCCESS);
- }
- void input(int * array, int size, int *num_inputs) {
- /* Reads input
- * Writes into array
- * Records the number of numbers in array
- */
- int i = 0;
- printf("Enter numbers:\n");
- while( scanf("%d", &array[i]) != EOF ) {
- i++;
- (*num_inputs)++;
- if (i == (size-1))
- break;
- }
- }
- void findingsmaller (int *array, int num_inputs){
- /* Finds a number that is smaller than the one on its left
- * Enters "toleft" which places it somewhere on the left
- * Keep doing it until I'm at the end of array
- */
- int a = 0;
- int b = 1;
- for ( b=1; b == num_inputs-1; b++ ) {
- if ( array[a] > array[b] ) {
- goleft(array, a, b);
- a++;
- }
- }
- }
- void goleft(int *array, int a, int b) {
- /* Goes left in an array until it finds a number smaller, then keeps it there
- */
- int temp;
- printf("Hello \n"); //testing whether function entered
- do {
- temp = array[a]; //replace
- array[a] = array[b];
- array[b] = temp;
- a--;
- b--;
- } while ( a > 0 || array[a] > array[b] ); //do this until we reach the end or smaller
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement