hello - int rightPos = leftHi+1; int count = rightHi leftLo...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# include <stdio.h>   // standard input output  # include <stdlib.h>    // standard library gcc hello.c -o hello <enter> ./hello  #define SIZE 200  int list[SIZE];  void sort();  int main(){  srand(time(NULL));  int i;  for(i = 0 i < 15; i++){  list[i] = rand()%90+10;  printf("Hello World!\n");  return 0;  public void sort() {  int numElements = 10;  int extra[] = numElements;  mergeSort(0, numElements-1, extra);  void mergeSort(int lo, int hi, int extra[]) {  if (lo < hi) {    int mid = (lo+hi) / 2;    mergeSort(lo, mid, extra);     mergeSort(mid+1, hi, extra);    merge(extra, lo, mid, hi); 
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  }    }  void merge(int extra[], int leftLo, int leftHi, int rightHi) {  
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int rightPos = leftHi+1; int count = rightHi leftLo + 1; int extraPos = leftLo; int LeftPos = leftLo; while ((leftPos &lt;= leftHi) &amp;&amp; (rightPos &lt;= rightHi)) if(list[leftPos] &lt; list[rightPos]){ extra[extraPos] = list[leftPos]; extraPos++; leftPos++; } else { extra[extraPos] = list[rightPos]; extraPos++; rightPos++; } while (leftPos &lt;= leftHi){ extra[extraPos] = list[leftPos]; extraPos++; leftPos++; } while (rightPos &lt;= rightHi){ extra[extraPos] = list[rightPos]; extraPos++; rightPos++; } for (int k = leftLo; k &lt;= rightHi; k++) list[k] = extra[k]; }...
View Full Document

Page1 / 2

hello - int rightPos = leftHi+1; int count = rightHi leftLo...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online