1 / 10

Lecture 10

Lecture 10. STL & Data Structure & Algorithm. vector. vector<string> SS; SS.push_back("The number is 10"); SS.push_back("The number is 20"); for(int ii=0; ii < SS.size(); ii++) { cout << SS[ii] << endl; }. vector. Continous Storage. What about deleting one element in the middle?.

holli
Download Presentation

Lecture 10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 10 STL & Data Structure & Algorithm

  2. vector vector<string> SS; SS.push_back("The number is 10"); SS.push_back("The number is 20"); for(int ii=0; ii < SS.size(); ii++) { cout << SS[ii] << endl; }

  3. vector • Continous Storage. • What about deleting one element in the middle? CSE459.22 Programming in C++ Au09, The Ohio State University

  4. List  list<int> L;  L.push_back(0); L.push_front(0);    list<int>::iterator i; for(i=L.begin(); i != L.end(); ++i) cout << *i << " "; CSE459.22 Programming in C++ Au09, The Ohio State University

  5. List • Non-continous Storage • Randomly delete one element efficiently. CSE459.22 Programming in C++ Au09, The Ohio State University

  6. Map map<int, string> Employees; Employees[5234] = "Mike C."; Employees[3374] = "Charlie M."; Employees[1923] = "David D."; cout << "Employees[3374]=" << Employees[3374] << endl << endl; CSE459.22 Programming in C++ Au09, The Ohio State University

  7. Queue queue<int> Q; Q.push(8); Q.push(7); Q.push(6); Q.pop(); //pop 8 Q.pop(); // pop 7 Q.pop(); // pop 6 CSE459.22 Programming in C++ Au09, The Ohio State University

  8. priority_queue priority_queue<int> mypq; mypq.push(30); mypq.push(100); mypq.push(25); while (!mypq.empty()) { cout << " " << mypq.top(); mypq.pop(); } //Output: 100 30 25 CSE459.22 Programming in C++ Au09, The Ohio State University

  9. priority_queue priority_queue <int, vector<int>, greater<int> > pq; /*pq is a priority queue of integers that uses a vector of integers for storage and uses > to determine priority. This means that if a > b, a has *lower* priority than b.*/ • pq.push(2); //put 2, 5, 3, 1 into the queue • pq.push(5); • pq.push(3); • pq.push(1); • while (!pq.empty()) { • cout << pq.top() << endl; • pq.pop(); //output 1 2 3 5 • } CSE459.22 Programming in C++ Au09, The Ohio State University

  10. priority_queue • See Height.pdf CSE459.22 Programming in C++ Au09, The Ohio State University

More Related