DOC PREVIEW
DREXEL CS 265 - Week 1

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Week 1Programming Style (C++)Basic components of STLPowerPoint PresentationSlide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Week 11. Programming Style2. Standard Template Library3. Merge-Sort AlgorithmProgramming Style (C++) 1. Names of functions, classes, structures, variables and constants2. Expressions and statements 3. CommentsBasic components of STL1. Containers2. Algorithms 3. IteratorsOnline documentation & linkshttp://www.sgi.com/tech/stl/Merge algorithm:OutputIterator merge(InputIterator1 first1,InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result);Merge combines two sorted ranges [first1, last1) and [first2, last2) into a single sorted range. That is, it copies elements from [first1, last1) and [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) such that the resulting range is in ascending order. The return value is result + (last1 - first1) + (last2 - first2).Include statements:#include <vector>#include <algorithm> Type definitions:typedef vector<int> IntVector;typedef IntVector::iterator IntVectorIt;//Allocate a vector of size n//Define an iterator and its initial and //terminal valuesIntVector Vector1(n);IntVectorIt start1,end1,it1;start1 = Vector1.begin();end1 = Vector1.end();//Enter n consecutive even numbers into vector 1int i=0;for(it1=start1;it1!=end1;it1++){ *it1=2*i;i++;}//Perform merging of vectors 1 and 2 into vector 3merge(start1,end1,start2,end2,start3);Sort Algorithm:void sort(RandomAccessIterator first, RandomAccessIterator last);Sort sorts the elements in [first, last) into ascending order, meaning that if i and j are any two valid iterators in [first, last) such that i precedes j, then *j is not less than *i.//Enter random numbers into NumbersVectorfor(itv=startv;itv!=endv;itv++)*itv=rand()%n; //Start timing sorting procedureclock_t start=clock();sort(startv,endv);//Stop timing sorting procedureclock_t stop=clock();//Print out elapsed time in milisecondscout << "The elapsed time: ";cout << 1000*(stop-start) /CLOCKS_PER_SEC <<


View Full Document

DREXEL CS 265 - Week 1

Download Week 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Week 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Week 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?