1 / 10

Abstrakta Containertyper

Abstrakta Containertyper. Vilka finns fördefinierade? Vad kan dom? #pragma warning(disable:4786). Sekventiell container. innehåller en ordnad följd av element. Följande typer finns: vector Specialfall “deque”, optimerad för köer lista. 0. 1. 2. 3. 4. vector<Type>. size capacity

Download Presentation

Abstrakta Containertyper

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. Abstrakta Containertyper • Vilka finns fördefinierade? • Vad kan dom? • #pragma warning(disable:4786) CD5250 OOP med C++ Daniel Flemström MDH/IDT

  2. Sekventiell container innehåller en ordnad följd av element. Följande typer finns: • vector • Specialfall “deque”, optimerad för köer • lista CD5250 OOP med C++ Daniel Flemström MDH/IDT

  3. 0 1 2 3 4 vector<Type> CD5250 OOP med C++ Daniel Flemström MDH/IDT

  4. size capacity reserve resize push_back push_front [ ] begin end insert element/sequence erase element/sequence operator= empty vector(vec.pos1,vec.pos2) find Vector< > Exempel på medlemsfunktioner CD5250 OOP med C++ Daniel Flemström MDH/IDT

  5. list<Type> CD5250 OOP med C++ Daniel Flemström MDH/IDT

  6. size insert element/sequence push_back push_front sort reverse begin end erase element/sequence operator= empty list(list2.pos1,list2.pos2) merge List< >Exempel på medlemsfunktioner CD5250 OOP med C++ Daniel Flemström MDH/IDT

  7. Iteratoranvändning vector<string>::iterator it;. . . for (it = myVect.begin(); it!= myVect.end(); it++) { cout << * it << endl; } CD5250 OOP med C++ Daniel Flemström MDH/IDT

  8. Associativ container Stöder effektiv sökning Följande typer finns: • map - (nyckel, värde) - par • set - visst element finns/finns inte • multimap, multiset: som map, set men det kan finnas flera par/element med samma nyckel CD5250 OOP med C++ Daniel Flemström MDH/IDT

  9. map<Type1, Type2> #include <map> . . . map <string,int> myPhonebook; myPhonebook.insert(make_pair(string(“Joe”), 123456)); . . . int joes_number = myPhonebook[“Joe”]; . . . myPhonebook.erase(“Joe”); CD5250 OOP med C++ Daniel Flemström MDH/IDT

  10. set<Type> #include <set> set <int> lucky_numbers; lucky_numbers.insert(3); lucky_numbers.insert(7); lucky_numbers.insert(13); CD5250 OOP med C++ Daniel Flemström MDH/IDT

More Related