CIS275LabProject2 - CIS 275, Fall 2007 LAB PROJECT 2 Source...

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

View Full Document Right Arrow Icon
LAB PROJECT 2 Source Code #include <iostream> #include <list> #include <algorithm> #include <iterator> using namespace std; int a[50]; void merge( int , int , int ); void merge_sort( int low, int high) { if (low==high) return ; //if the boundaries are the same, the sublist has only one element, and cannot be further split int middle; if (low<high) { middle=(low+high)/2; merge_sort(low,middle); //sort the first half merge_sort(middle+1,high); //sort the second half merge(low,middle,high); //merge both sublists } } void merge( int low, int middle, int high) { int l,i,j,b[50],k; l=low; //the first element in the first sublist i=low; j=middle+1; //the first element in the second sublist while { if (a[l]<=a[j]) //if two lists exist and the current element in the low is smaller than the high, insert it into the next position in the output array and move to the next element in the low list. { b[i]=a[l];
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/06/2008 for the course CIS 275 taught by Professor Campfner during the Fall '07 term at University of Michigan.

Page1 / 3

CIS275LabProject2 - CIS 275, Fall 2007 LAB PROJECT 2 Source...

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