MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A. C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction.

Slides:



Advertisements
Similar presentations
Handy Time Vocab 2 - Days of the week With Miss Digitally Angry Clock-Face.
Advertisements

Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Chapter 3 Lists Dr Zeinab Eid.
Stacks, Queues, and Linked Lists
Linked Lists Chapter 4.
Queues and Linked Lists
Lists A list is a finite, ordered sequence of data items. Important concept: List elements have a position. Notation: What operations should we implement?
Linked Lists Definition of Linked Lists Examples of Linked Lists
CS 367 – Introduction to Data Structures
© 2004 Goodrich, Tamassia Node-Lists1 6.2 Node Lists.
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Lists1 © 2010 Goodrich, Tamassia. Position ADT The Position ADT models the notion of place within a data structure where a single object is stored It.
Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
Linked lists CSCI 2170.
Generics, Lists, Interfaces
Its not every day that you get to do something special, but on occasion it happens!
Array-Based Lists List Length of a list
Ics202 Data Structures. hh tail head (b) LinkedList head tail Element datum next 3 Integer Element datum next 1 Integer Element datum next 4 Integer.
M180: Data Structures & Algorithms in Java
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
TEST YOUR READING SKILLS : See a day of the week written in French. Say what you think it is. Click to check your answer.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Array Lists Chapter 7.2 Pages Array Lists In Java, Arrays are an important structure for storing data. We will learn more about arrays later,
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Rossella Lau Lecture 3, DCO20105, Semester A, DCO Data structures and algorithms  Lecture 3: Basics of Linked List  C++ pointer revision.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
C++ for Engineers and Scientists Third Edition
Chapter 3: Arrays, Linked Lists, and Recursion
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
C++ Classes and Data Structures Jeffrey S. Childs
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
Data collections Android Club Agenda Array ArrayList HashMap.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
LINKED LIST’S EXAMPLES Salim Malakouti. Linked List? 523 Pointer Node ValuePointer.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
1 Linked Multiple Queues. 2 A real world example. Not in the book. Sometimes we have a fixed number of items that move around among a fixed set of queues.
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
1 Chapter 16 Creating the Document and Improving the View.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
Linked Lists CS 367 – Introduction to Data Structures.
LINKED LISTS.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Linked Data Structures
CSCE 210 Data Structures and Algorithms
Lecture 6 of Computer Science II
LINKED LISTS CSCD Linked Lists.
Object Oriented Programming COP3330 / CGS5409
Linked Lists.
Chapter 17: Linked Lists.
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/11.
MFC Collection Classes
Introduction to Computer Science
Presentation transcript:

MFC C OLLECTION C LASSES Tr ầ n Anh Tu ấ n A

C ONTENTS ( MFC C OLLECTION C LASSES ) Array Introduction Example List Introduction Example Map Introduction Example

A RRAY Introduction : MFC Provides an assortment of array classes for users Header file Afxtempl.h A template class from which you can create type-safe arrays for data of any type Generic CArray Class Header file Afxcoll.h Is designed to hold a particular type of data Nontemplatized array classes

A RRAY Type-Specific MFC Array Classes

A RRAY Sample : CStringArray Construction CStringArray Constructs an empty array for CString objects.CStringArray Example : Bounds GetSize Gets number of elements in this array.GetSize GetUpperBound Returns the largest valid index.GetUpperBound SetSize Sets the number of elements to be contained in this array.SetSize Example : Operators operator [] Sets or gets the element at the specified index.operator []

A RRAY Sample : CStringArray Operations FreeExtra Frees all unused memory above the current upper bound.FreeExtra RemoveAll Removes all the elements from this array.RemoveAll Example : Element Access GetAt Returns the value at a given index.GetAt SetAt Sets the value for a given index; array not allowed to grow.SetAt ElementAt Returns a temporary reference to the element pointer within the array.ElementAt GetData Allows access to elements in the array. Can be NULL.GetData Example :

A RRAY CStringArray Class Members Growing the Array SetAtGrow Sets the value for a given index; grows the array if necessary.SetAtGrow Add Adds an element to the end of the array; grows the array if necessary.Add Append Appends another array to the array; grows the array if necessary.Append Copy Copies another array to the array; grows the array if necessary.Copy Example : Insertion/Removal InsertAt Inserts an element (or all the elements in another array) at a specified index.InsertAt RemoveAt Removes an element at a specific index.RemoveAt Example :

A RRAY Generic CArray Class A template class used to build type-safe array classes for arbitrary data types, such as array of CPoint Users can use data of any kind—even classes of your own creation—in CArray 's template parameters Example : Create an array of CPoint : CArray array; Create an array of SinhVien : CArray array; array.SetSize(10); Array.Add(SinhVien(“Tran Van Huy”,” ”,”Nam”); CArray variable

A RRAY Example : Request Use Array to store and view a list of SinhVien Step 1 New a project Create SinhVien Class in your project Step 2 Add a list of SinhVien into array Make the operation of viewing SinhVien Data

E XAMPLE : S TEP 1 SinhVien.h SinhVien.cp p Note: must make class Dialog to be a friend of class SinhVien to access SinhVien data (Hoten and MSSV)

E XAMPLE : S TEP 2 Class Winzards Collection Demo Dialog CollectionDemoDlg. h CollectionDemoDlg::OnInitDialog()

E XAMPLE : O UTPUT

L IST A linked list is a collection of items that contain pointers to other items ( Next and Prev pointer). The MFC template class CList implements a generic linked list that can be customized to work with any data type POSITION : A value used to denote the position of an element in a collection; used by MFC collection classes

L IST Sample : CObList Construction CObList Constructs an empty list for CObject pointers. Head/Tail Access CObList GetHead Returns the head element of the list (cannot be empty). GetHead GetTail Returns the tail element of the list (cannot be empty). GetTail Operations RemoveHead Removes the element from the head of the list. RemoveHead RemoveTail Removes the element from the tail of the list. RemoveTail AddHead Adds an element (or all the elements in another list) to the head of the list (makes a new head). AddHead AddTail Adds an element (or all the elements in another list) to the tail of the list (makes a new tail). AddTail RemoveAll Removes all the elements from this list. RemoveAll

L IST Sample : CObList Iteration GetHeadPosition Returns the position of the head element of the list. GetHeadPosition GetTailPosition Returns the position of the tail element of the list. GetTailPosition GetNext Gets the next element for iterating. GetNext GetPrev Gets the previous element for iterating. GetPrev Retrieval/Modification GetAt Gets the element at a given position. GetAt SetAt Sets the element at a given position. SetAt RemoveAt Removes an element from this list, specified by position. RemoveAt

L IST Sample : CObList Insertion InsertBefore Inserts a new element before a given position. InsertBefore InsertAfter Inserts a new element after a given position. InsertAfter Searching Find Gets the position of an element specified by pointer value. Find FindIndex Gets the position of an element specified by a zero-based index. FindIndex Status GetCount Returns the number of elements in this list. GetCount IsEmpty Tests for the empty list condition (no elements). IsEmpty

L IST Generic CList Class A template class used to build type-safe list classes for arbitrary data types, such as array of CPoint Users can use data of any kind—even classes of your own creation—in CList 's template parameters Example : Create a list of CPoint : CList list; Create an list of Book : CList list; list CList variable

L IST Example : Request Use List to store and view a list of Book Step 1 New a project Create Book Class in your project Step 2 Add a list of Book into list Make the operation of viewing Book Data

E XAMPLE : STEP 1 Book.h Book.cpp

E XAMPLE : S TEP 2 Class Winzards CCObListDemoDlg.h CCObListDemoDlg::OnInitDial og()

E XAMPLE : O UTPUT

M AP A map, also known as a dictionary, is a table of items keyed by other items Maps are ideal containers for large amounts of data when lookup performance is of paramount importance

M AP MFC provides the following type-specific (and non-template-based) map classes Each class includes member functions for adding and removing items, retrieving items by key, and enumerating all the items in the map

M AP Sample : CMapStringToString Initialize Mapping CMapStringToString map; map[_T ("Sunday")] = _T ("Dimanche"); map[_T ("Monday")] = _T ("Lundi"); map[_T ("Tuesday")] = _T ("Mardi"); map[_T ("Wednesday")] = _T ("Mercredi"); map[_T ("Thursday")] = _T ("Jeudi"); map[_T ("Friday")] = _T ("Vendredi"); map[_T ("Saturday")] = _T ("Samedi");

M AP Sample : CMapStringToString (More in MSDN) Look up CString string; if (map.Lookup (_T ("Thursday"), string)) TRACE (_T ("Thursday in English = %s in French\n"), string); POSITION pos = map.GetStartPosition (); while (pos != NULL) { CString strKey, strItem; map.GetNextAssoc (pos, strKey, strItem); TRACE (_T ("Key=%s, Item=%s\n"), strKey, strItem); }

E ND OF W EEK 4