1 / 7

Arrays and Collections

Arrays and Collections. Arrays One dimensional array Two or multiple dimensional array Collections Standard collection: ArrayList Generic collection: LinkedList. Array in C++/CLI. Array, element, index(or subscript) array<int> ^ a = gcnew array<int>(12);

Download Presentation

Arrays and Collections

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. Arrays and Collections • Arrays • One dimensional array • Two or multiple dimensional array • Collections • Standard collection: ArrayList • Generic collection: LinkedList

  2. Array in C++/CLI • Array, element, index(or subscript) • array<int> ^ a = gcnew array<int>(12); • array<int> ^ a = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; • a[0], a[1],…, and a[11] • a->Length • array<String ^> ^d = {“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”}; • int main(array<System::String ^> ^args) {}

  3. Array in C++/CLI • Multi-dimensional Array • array<int, 2> ^ b = gcnew array<int, 2>(4,3); • array<int, 2> ^ b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; • b[0,0], b[0,1],…, b[3,2]; • b->Rank, b->GetLength(0), b->GetLength(1)

  4. Collections in C++/CLI • ArrayList(System::Collections Namespace) • Index-based • Constant-time random access • consecutive • Dynamically growing arrays, re-sizeable • LinkedList(System::Collections::Generic Namespace) • Traverse the list to find the proper node • Dis-contiguous

  5. Collections in C++/CLI • ArrayList ^ list1 = gcnew ArrayList(); • Property: Count • Methods: [], Add, Insert, RemoveAt, Clear

  6. Collections in C++/CLI • LinkedList<String^> ^list2 = gcnew LinkedList<String^>(); • LinkedListNode<String^> ^cur; cur->Value, cur->Next; cur->Previous • Property: Count, First, Last • Methods: AddFirst, AddLast, AddBefore, AddAfter, RemoveFirst, RemoveLast, Remove, Clear

  7. Exercise • Create an array with fixed length containing “Monday”, “Tuesday”,…….“Sunday”, and print the array. • Create an array which is able to hold arbitrary number of student names, add n names and finally print. • ArrayList • LinkedList

More Related