本文整理汇总了C++中List::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ List::Append方法的具体用法?C++ List::Append怎么用?C++ List::Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List::Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: partition_list
void partition_list(List &list, int x) {
if (list.Head() == NULL) { return; }
List small;
List large;
Node *pre = list.Head();
while (pre != NULL) {
if (pre->Data() <= x) {
small.Append(pre->Data());
} else {
large.Append(pre->Data());
}
pre = pre->Next();
}
if (small.Head() != NULL) {
pre = small.Head();
while (pre->Next() != NULL) {
pre = pre->Next();
}
pre->SetNext(large.Head());
list.SetHead(small.Head());
} else {
list.SetHead(large.Head());
}
}
示例2: main
int main() {
// New list
List<int> list;
// Append nodes to the list
list.Append(100);
list.Print();
list.Append(200);
list.Print();
list.Append(300);
list.Print();
list.Append(400);
list.Print();
list.Append(500);
list.Print();
// Delete nodes from the list
list.Delete(400);
list.Print();
list.Delete(300);
list.Print();
list.Delete(200);
list.Print();
list.Delete(500);
list.Print();
list.Delete(100);
list.Print();
return 0;
}
示例3: writeUandLToFile
void writeUandLToFile() {
// wait for your turn
if (rank != 0) {
int predecessorDone = 0;
MPI_Status status;
MPI_Recv(&predecessorDone, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &status);
}
List<Dimension*> *udimLengths = new List<Dimension*>;
udimLengths->Append(&uDims[0]);
udimLengths->Append(&uDims[1]);
TypedOutputStream<double> *ustream = new TypedOutputStream<double>("/home/yan/u.bin", udimLengths, rank == 0);
List<Dimension*> *ldimLengths = new List<Dimension*>;
ldimLengths->Append(&lDims[0]);
ldimLengths->Append(&lDims[1]);
TypedOutputStream<double> *lstream = new TypedOutputStream<double>("/home/yan/l.bin", ldimLengths, rank == 0);
List<int> *indexList = new List<int>;
int blockStride = blockSize * processCount;
int storeIndex = 0;
ustream->open();
lstream->open();
for (int i = blockSize * rank; i < aDims[0].length; i+= blockStride) {
int start = i;
int end = start + blockSize - 1;
if (end >= aDims[0].length) end = aDims[0].length - 1;
for (int r = start; r <= end; r++) {
for (int j = 0; j < aDims[1].length; j++) {
indexList->clear();
indexList->Append(r);
indexList->Append(j);
ustream->writeElement(u[storeIndex], indexList);
lstream->writeElement(l[storeIndex], indexList);
storeIndex++;
}
}
}
ustream->close();
lstream->close();
delete indexList;
delete ustream;
delete lstream;
// notify the next in line
if (rank < processCount - 1) {
int writingDone = 1;
MPI_Send(&writingDone, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
}
}
示例4: LinearizeCurve
EXP
void LinearizeCurve( int max_iter,
const int n, const int p, Ptr< T > U, Ptr< HP > Pw,
const T tol, const rtl<T>& t,
int *ret_nP, Ptr< EP > *retP )
{
List< ListNode<EP> > L;
ListNode<EP> *node = new ListNode<EP>(euclid(Pw[0]));
int i,nEl;
Ptr< EP > P;
L.Append( node );
LinearizeCurve( max_iter, n, p, U, Pw, tol, t,
LinearizeLineCallback<EP>, (void *)&L );
nEl = L.nElems;
node = L.head;
P.reserve_pool( nEl );
for( i = 0; i < nEl; i++ )
{
P[nEl-1-i] = node->el;
node = node->next;
}
*ret_nP = nEl;
*retP = P;
L.DeleteElems();
}
示例5: GetGameTime
Animation * Animation::AddAnimation(Object * source) const
{
if (GetState() == true)
{
ActiveAnimations.Append(new Animation);
Animation * newAnim = ActiveAnimations.GetLast();
newAnim->Copy(*this);
newAnim->source = source;
const char * animScript = script.GetScript();
newAnim->script.LoadScript(animScript, newAnim);
const char * onAddScript = onAdd.GetScript();
newAnim->onAdd.LoadScript(onAddScript, newAnim);
newAnim->sprite = sprite;
newAnim->bounds = bounds;
newAnim->scalingCenter = scalingCenter;
newAnim->rotationCenter = rotationCenter;
newAnim->offset = offset;
newAnim->color = color;
newAnim->onAdd.ActivateScript(true);
newAnim->SetUInt32Value(ANIM_VAR_START_TIME, GetGameTime());
return newAnim;
}
return NULL;
}
示例6: main
int main()
{
List list;
cout << "output1" << endl;
list.OutputAllElements();
bool success;
for ( int i = 0; i < 6; i++ )
{
success = list.Append( i * 3 );
}
cout << "output2" << endl;
list.OutputAllElements();
cout << "Remove index 3" << endl;
list.Remove( 3 );
list.OutputAllElements();
cout << list.GetItemAtPosition( 3 ) << endl;
return 0;
}
示例7: readAFromFile
void readAFromFile(const char *filePath) {
TypedInputStream<double> *stream = new TypedInputStream<double>(filePath);
int storeIndex = 0;
int blockStride = blockSize * processCount;
List<int> *indexList = new List<int>;
stream->open();
for (int i = 0; i < aDims[0].length; i++) {
for (int j = blockSize * rank; j < aDims[1].length; j += blockStride) {
int start = j;
int end = start + blockSize - 1;
if (end >= aDims[1].length) end = aDims[1].length - 1;
for (int c = start; c <= end; c++) {
indexList->clear();
indexList->Append(i);
indexList->Append(c);
a[storeIndex] = stream->readElement(indexList);
storeIndex++;
}
}
}
stream->close();
delete indexList;
delete stream;
}
示例8:
bool BoolTable::
GenerateMaxTrueABVList( List<AnnotatedBoolVector> &result )
{
if( !initialized ) {
return false;
}
AnnotatedBoolVector *abv;
int frequency = 0;
bool *seen = new bool[numCols];
bool *tempContexts = new bool[numCols];
for( int col = 0; col < numCols; col ++ ) {
seen[col] = false;
tempContexts[col] = false;
}
bool hasCommonTrue = false;
// find maximum colTotalTrue value
int maxTotalTrue = 0;
for( int i = 0; i < numCols; i++ ) {
if( colTotalTrue[i] > maxTotalTrue ) {
maxTotalTrue = colTotalTrue[i];
}
}
// only create ABVs for cols with max colTotalTrue values
for( int i = 0; i < numCols; i++ ) {
if( colTotalTrue[i] == maxTotalTrue ) { // check initial
if( !seen[i] ) {
frequency = 1;
tempContexts[i] = true;
for( int j = i + 1; j < numCols; j++ ) {
if( colTotalTrue[j] == maxTotalTrue ) { // check compare
if( !seen[j] ){
CommonTrue( i, j, hasCommonTrue );
if( hasCommonTrue ) {
frequency++;
seen[j] = true;
tempContexts[j] = true;
}
}
}
}
abv = new AnnotatedBoolVector;
abv->Init( numRows, numCols, frequency );
for( int row = 0; row < numRows; row++ ) {
abv->SetValue( row, table[i][row] );
}
for( int col = 0; col < numCols; col++ ) {
abv->SetContext( col, tempContexts[col] );
tempContexts[col] = false;
}
result.Append( abv );
}
}
}
delete [] seen;
delete [] tempContexts;
return true;
}
示例9: BoolVector
bool BoolTable::
GenerateMaximalTrueBVList( List< BoolVector > &result )
{
BoolVector *newBV = NULL;
BoolVector *oldBV = NULL;
for( int i = 0; i < numCols; i++ ) {
newBV = new BoolVector( );
newBV->Init( numRows );
for( int row = 0; row < numRows; row++ ) {
newBV->SetValue( row, table[i][row] );
}
result.Rewind( );
bool addBV = true;
bool isSubset = false;
while( result.Next( oldBV ) ) {
newBV->IsTrueSubsetOf( *oldBV, isSubset );
if( isSubset ) {
addBV = false;
break;
}
oldBV->IsTrueSubsetOf( *newBV, isSubset );
if( isSubset ) {
result.DeleteCurrent( );
}
}
if( addBV ) {
result.Append( newBV );
} else {
delete newBV;
}
}
return true;
}
示例10:
List<T> * List<T>::Clone() const
// returns pointer to a copy of *this
{
List * clone = new List;
clone->Append(*this);
return clone;
}
示例11: main
void main() {
Recipe myRecipe1 = Recipe("Fish Filets in Hot Chili Oil");
Recipe myRecipe2 = Recipe("Boiled Fish with Pickled Cabbage and Chili ");
Recipe myRecipe3 = Recipe("Coke Chicken");
Recipe myRecipe4 = Recipe("Fish ball soup");
List<Recipe>* myRecipeList = new List<Recipe>();
myRecipeList->Append(myRecipe1);
myRecipeList->Append(myRecipe2);
myRecipeList->Append(myRecipe3);
myRecipeList->Append(myRecipe4);
ListIterator<Recipe> myIterator = ListIterator<Recipe>(myRecipeList);
for(myIterator.First(); !myIterator.IsDone(); myIterator.Next()) {
myIterator.CurrentItem().Print();
}
while(1) {
;
}
}
示例12: AnimationMaintenance
void AnimationMaintenance()
{
while (RemovedAnimations.GetSize() > 0)
{
if (RemovedAnimations[0] != NULL)
{
delete RemovedAnimations[0];
}
RemovedAnimations.Remove(0);
}
ActiveAnimations.ToStart();
for (int32 i = 0; i < ActiveAnimations.GetSize(); i++)
{
Animation * animation = ActiveAnimations.GetCurrent();
Object * source = animation->GetSource();
ActiveAnimations.ToNext();
if ((source != NULL) && (source->GetState() == false))
{
animation->SetSource(NULL);
}
if (animation != NULL)
{
if (animation->GetState() == false)
{
RemovedAnimations.Append(animation);
ActiveAnimations.Remove(i);
i--;
}
else
{
Object * source = animation->GetSource();
uint32 duration = animation->GetUInt32Value(ANIM_VAR_DURATION);
uint32 startTime = animation->GetUInt32Value(ANIM_VAR_START_TIME);
if (((duration == 0) && (source != NULL) && (source->GetState() == true)) || ((GetGameTime() - startTime) < duration))
{
animation->ActivateScript();
}
else
{
animation->Unload();
}
}
}
else
{
ActiveAnimations.Remove(i);
i--;
}
}
}
示例13: writeAToFile
void writeAToFile() {
// wait for your turn
if (rank != 0) {
int predecessorDone = 0;
MPI_Status status;
MPI_Recv(&predecessorDone, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &status);
}
List<Dimension*> *dimLengths = new List<Dimension*>;
dimLengths->Append(&aDims[0]);
dimLengths->Append(&aDims[1]);
TypedOutputStream<double> *stream = new TypedOutputStream<double>("/home/yan/a-copy.bin", dimLengths, rank == 0);
int storeIndex = 0;
List<int> *indexList = new List<int>;
int blockStride = blockSize * processCount;
stream->open();
for (int i = 0; i < aDims[0].length; i++) {
int aRow = i * aDims[1].length;
for (int j = blockSize * rank; j < aDims[1].length; j += blockStride) {
int start = j;
int end = start + blockSize - 1;
if (end >= aDims[1].length) end = aDims[1].length - 1;
for (int c = start; c <= end; c++) {
indexList->clear();
indexList->Append(i);
indexList->Append(c);
stream->writeElement(a[storeIndex], indexList);
storeIndex++;
}
}
}
stream->close();
delete indexList;
delete stream;
// notify the next in line
if (rank < processCount - 1) {
int writingDone = 1;
MPI_Send(&writingDone, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
}
}
示例14: main
int main( )
{
// New list
List list;
// Append nodes to the list
list.Append( 100 );
list.Print( );
list.Append( 200 );
list.Print( );
list.Append( 300 );
list.Print( );
list.Append( 400 );
list.Print( );
list.Append( 500 );
list.Print( );
// Delete nodes from the list
list.Delete( 400 );
list.Print( );
list.Delete( 300 );
list.Print( );
list.Delete( 200 );
list.Print( );
list.Delete( 500 );
list.Print( );
list.Delete( 100 );
list.Print( );
std::list<int> myList;
myList.push_back( 5 );
myList.push_front( 3 );
myList.push_back( 9 );
myList.remove( 5 );
for ( auto it = myList.begin(); it != myList.end(); it++ )
cout << ( *it ) << endl;
return 0;
}
示例15:
void GenericQuery::
copyStringCategory (List<char> &to, List<char> &from)
{
char *item;
clearStringCategory (to);
from.Rewind ();
while ((item = from.Next ()))
to.Append (new_strdup (item));
}