All pastes #455246 Raw Edit

Someone

public c v1 · immutable
·published 2007-04-24 02:27 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>/* 2D point structure */typedef struct {  int x;  int y;} point;void selectionSort(point* array, int size);int main(){  int i;  int size = 10;  point* points = (point*)malloc(sizeof(point) * size);  printf("Unsorted:\n");  for (i = 0 ; i < size ; i++)  {    points[i].x = rand() / (float)RAND_MAX * 20;    /* randomize points with */    points[i].y = rand() / (float)RAND_MAX * 20;    /* values up to 20       */    printf("x = %d, y = %d\n", points[i].x, points[i].y);  }  printf("\n");  selectionSort(points, size);  printf("Sorted:\n");  for (i = 0 ; i < size ; i++)  {    printf("x = %d, y = %d\n", points[i].x, points[i].y);  }  return 0;}/*** Function void selectionSort** Sorts numbers in array** This function sorts the numbers in an array from smallest to largest** Arguments** 1) array - the array of integers to sort* 2) size - the size of the array*/void selectionSort(point* array, int size){  int i,j,min,tempx,tempy;  for (i = 0; i < size-1; i++) { // Start looping through the array    min = i;    for(j = i+1; j < size; j++) { // Here we check the next value for size      if(array[j].x < array[min].x) {        min = j;      }    }    tempx = array[i].x; // Here we Swap the values    tempy = array[i].y;    array[i].x = array[min].x;    array[i].y = array[min].y;    array[min].x = tempx;    array[min].y = tempy;  }}