List

xiaoxiao2021-03-06  67

Applying for this Blog has been a long time. Today, I finally calmed down, write some Dongdong.

The development of 2D games in the near future.

Many places in the program use List. Talk about it simple to talk about it now. Be a start. :)

We often need to traverse a list.

as follows:

Struct Sitem

{

INT X;

Int Y;

}

Typedef List Lsitem;

Typedef List :: Iterator iTerItem

Lsitem mylist;

Iteritem it = mylist.begin (); it! = mylist.end (); iter )

{

Sitem * Pitem = (Sitem *) & (* iter);

// pitem-> x ........

}

This method is very common.

However, if we need to increase or delete the LIST during traversing process?

Iteritem it = mylist.begin (); it! = mylist.end (); iter )

{

Sitem * Pitem = (Sitem *) & (* iter);

IF (pitem-> x == 1)

MyList.rase (iTer);

}

This way is obviously wrong! Because of the erase (iter), iTer does not know where to point.

So we can use:

iterItem it = mylist.begin ();

While (True)

{

IF (myList.empty () || t == mylist.end ())

Break;

iTerItem ITERNEXT = ITER;

ITERNEXT ;

// Process this node

IF (pitem-> x == 1)

MyList.rase (iTer);

iter = iTernext; // Continue to process the next node

}

Ok, write this today.

Later, it will be placed in DirectX how to create a Control >> in Windows in DirectX.

If you have a leak, please refer to you. :)

转载请注明原文地址:https://www.9cbs.com/read-87531.html

New Post(0)