美文网首页
链表类CList成员的使用

链表类CList成员的使用

作者: Drlilian | 来源:发表于2019-06-17 10:29 被阅读0次

2009-04-29

链表类CList成员的使用

使用时 要

#include <afxtempl.h>

Construction

CListConstructs an empty ordered list.

建立一个链表

example:

CList<int,int> myList;//建立一个int链表

CList<CString,CString&> myList(16);//建立一个cstring的链表,后面的16表示链表里面数据的个数,如果不写的话,可能是不限个数?

CList<MYTYPE,MYTYPE&> myList;//建立一个MYTYPE类型(自定义)的链表

如果不存入数据的话,刚建立的链表是空的,头尾都为空

Head/Tail Access

GetHeadReturns the head element of the list (cannot be empty).

返回链表的头数据

例子:

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

int tmp=myList.GetHead();//tmp被赋予了0

GetTailReturns the tail element of the list (cannot be empty).

返回链表的尾数据

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

int tmp=myList.GetTail();//tmp被赋予了9999

Operations

RemoveHeadRemoves the element from the head of the list.

移除链表头数据,链表数据个数减1,返回缩减前的头数据

例子:

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

int tmp=myList.RemoveHead();//tmp被赋予了之前的头数据:0;同时数据个数变为9999;

RemoveTailRemoves the element from the tail of the list.

移除链表尾数据,链表数据个数减1,返回缩减前的尾数据

例子:

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

int tmp=myList.RemoveTail();//tmp被赋予了之前的尾数据:9999;同时数据个数变为9999;

AddHeadAdds an element (or all the elements in another list) to the head of the list (makes a new head).

在链表头处插入新数据,链表数据个数加1,返回新的链表头位置(POSITION);

例子:

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.AddHead(int(314));//链表有了一个新的头数据:314;同时链表个数变为10001;pos为新的头的位置;

AddTailAdds an element (or all the elements in another list) to the tail of the list (makes a new tail).

在链表尾处插入新数据,链表数据个数加1,返回新的链表尾位置(POSITION);

例子:

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.AddTail(int(314));//链表有了一个新的尾数据:314;同时链表个数变为10001;pos为新的尾的位置;

RemoveAllRemoves all the elements from this list.

清空链表,其头尾皆变成空指针;

Iteration

GetHeadPositionReturns the position of the head element of the list.

返回链表头的位置;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetHeadPosition();//获得链表头的位置

GetTailPositionReturns the position of the tail element of the list.

返回链表尾的位置;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetTailPosition();//获得链表尾的位置

GetNextGets the next element for iterating.

返回当前位置的数据,之后,位置后移一位;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetHeadPosition();//获得链表头的位置

int tmp=myList.GetNext(pos);//tmp被赋予了头数据的值:0;同时pos指向第二个数据1;

GetPrevGets the previous element for iterating.

返回当前位置的数据,之后,位置前移一位;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetTailPosition();//获得链表尾的位置

int tmp=myList.GetNext(pos);//tmp被赋予了尾巴数据的值:9999;同时pos指向倒数第二个数据9998;

Retrieval/Modification

GetAtGets the element at a given position.

返回指定位置的数据;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetTailPosition();//获得链表尾的位置,还可以继续改变pos,以指向其他数据

int tmp=myList.GetAt(pos);//tmp被赋予链表尾的数据

SetAtSets the element at a given position.

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetTailPosition();//获得链表尾的位置,还可以继续改变pos,以指向其他数据

myList.SetAt(pos,int(222));//将链表尾部的数据赋成222

RemoveAtRemoves an element from this list, specified by position.

清除指定位置处的数据;同时数据个数减1;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetTailPosition();//获得链表尾的位置

myList.RemoveAt(pos);//链表pos(尾部)位置的数据被清除,数据个数变为9999;

Insertion

InsertBeforeInserts a new element before a given position.

在指定位置前插入一个新数据,数据个数加1;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetHeadPosition();//获得第一个数据的位置

myList.InsertBefore(pos,int(123));//在第一个数据前插入一个新数据: 123,同时数据个数变为10001

InsertAfterInserts a new element after a given position.

在指定位置后插入一个新数据,数据个数加1;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.GetHeadPosition();//获得第一个数据的位置

myList.InsertAfter(pos,int(123));//在第一个数据后插入一个新数据: 123,同时数据个数变为10001

Searching

FindGets the position of an element specified by pointer value.

返回指定数据对应的位置;

CList<int,int> myList;

for(int i=0;i<10000;i++) { myList.AddTail(int(i)); }//存入数据

POSITION pos=myList.Find(int(0));//获得0(链表头)的位置

FindIndexGets the position of an element specified by a zero-based index.

返回索引号对应的位置;

POSITION pos=myList.FindIndex(0);//0表示链表头,以此类推

Status

GetCountReturns the number of elements in this list.

返回链表的数据个数

int num=myList.GetCount();//获得链表的数据个数

IsEmptyTests for the empty list condition (no elements).

判定链表是否为空;

返回1表示链表是空,返回0表示链表非空;

BOOL empty=myList.IsEmpty();

相关文章

  • 链表类CList成员的使用

    2009-04-29 链表类CList成员的使用 使用时 要 #include Construction CLis...

  • 2018-05-14

    双链表 双链表管理一个类的对象 //类 函数是共享的 数据是每个对象私有的//空指针 调用成员函数 没有访问数据...

  • iOS Objective-C中类的成员变量与属性

    类内使用成员变量{}, 类外使用属性@property. 参看 iOS --- Objective-C中类的成员变...

  • 使用C语言实现泛型

    Redis中的泛型链表 其中: 链表结点使用void*指针来保存节点值。 dup、free和match成员是用于实...

  • Java成员覆盖

    当子类覆盖父类的成员变量时,父类方法使用的是父类的成员变量,子类方法使用的是子类的成员变量。 这个听起来很容易理解...

  • 2020-07-04【反射】

    类加载 类加载器 反射概述 获取Class类的对象 反射获取构造方法并使用 反射获取成员遍历并使用 反射获取成员方...

  • C++基础2020-11-09

    C++ 类 & 对象 关键字 public 确定了类成员的访问属性 类的对象的公共数据成员可以使用直接成员访问运算...

  • Dart之旅07: 类

    Dart是面向对象语言,它是单继承的。所有类派生自Object 使用类成员 类成员和java一样,分为成员方法和成...

  • 面向对象

    类成员的定义 成员属性的定义 成员方法的定义 类成员的使用 构造方法 PHP不负责定义这个构造方法,只负责调用构造...

  • 关联对象

    一、类添加成员变量与分类添加成员变量的区别 (一)类 在 MJPerson 类中,使用 @property (no...

网友评论

      本文标题:链表类CList成员的使用

      本文链接:https://www.haomeiwen.com/subject/xhczxctx.html