beautypg.com

HP Integrity NonStop J-Series User Manual

Page 166

background image

we were searching for was found at position 1.

RWOrdered od;
od.insert(new RWCollectableInt(6)); // 6
od.insert(new RWCollectableInt(2)); // 6 2
od.insert(new RWCollectableInt(4)); // 6 2 4

RWCollectableInt dummy(2);
size_t inx = od.index(&dummy);
if (inx == RW_NPOS)
cout << "Not found.\n";
else
cout << "Found at index " << inx << endl;

Program Output:

Found at index 1

Finally, you can use the following function to insert an item at a particular index:

virtual RWCollectable* insertAt(size_t i, RWCollectable* c);

In the example below, the code uses the function insertAt to insert 4 at position 1.

RWOrdered od;
od.insert(new RWCollectableInt(6)); // 6
od.insert(new RWCollectableInt(2)); // 6 2
od.insertAt(1, new RWCollectableInt(4)); // 6 4 2

This manual is related to the following products: