Lab1 - CS 284 Algorithms Summer semester 2010 Lab 1 Lab...

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

View Full Document Right Arrow Icon
CS 284 Algorithms Summer semester 2010 Lab 1 Lab objectives: - Implement insertion sort and merge sort. - Compare the performance of insertion sort and merge sort. Related chapter(s): 2. Lab instructions (steps): 1. Write the following program: 1. #include <time.h> 2. #include <iostream> 3. #include <stdio.h> 4. void MergeSort( int A[], int left, int right); 5. void Merge( int D[], int left, int mid, int right); 6. void InsertionSort( int W[], int size); 7. void printArray( int A[], int n); 8. 9. using namespace std; 10. void main() 11. { 12. clock_t start1, finish1; 13. clock_t start2, finish2; 14. float Time1=0; // merge sort time 15. float Time2=0; // insertion sort time 16. unsigned long n=10; // input size 17. int MaxExp=10; 18. 19. //cout<<"n"<<'\t'<<"Merge"<<'\t'<<"Insertion"<<endl; 20. //for(int exp=1; exp<=MaxExp; exp++, n*=2){ 21. //create and intialize A with size n 22. int *A, *B; 23. srand ( time(NULL) ); 24. A= new int [n]; 25. B= new int [n]; 26. for ( int i=0; i<n; i++) {A[i]=(rand()); B[i]=A[i];}
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.

Page1 / 2

Lab1 - CS 284 Algorithms Summer semester 2010 Lab 1 Lab...

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