本文整理汇总了C++中LIST::getNode方法的典型用法代码示例。如果您正苦于以下问题:C++ LIST::getNode方法的具体用法?C++ LIST::getNode怎么用?C++ LIST::getNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LIST
的用法示例。
在下文中一共展示了LIST::getNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// and now a simple client to drive it all
int main()
{
int choice = 0; // user selection from menu, initialized to get into loop
LIST l; // the linked list itself
NODE *e; // for creating and removing nodes from the list
int key; // for access by key
// until user says to quit...
while( choice != QUIT )
{
// print the menu
cout << "\n0)\tinitialize list\n1)\tInsert front\n2)\tInsert rear\n"
<< "3)\tInsert by key\n4)\tRemove front\n5)\tRemove rear\n"
<< "6)\tRemove by key\n7)\tPrint list\n"
<< "8)\tCount of elements\n9)\tQuit\n\nEnter choice : " << flush;
cin >> choice;
switch( choice )
{
case INIT: l.init(); // initialize an empty list
break;
case INSERTFRONT: e = new NODE; // insert at front
cout << "Enter key and data : " << flush;
cin >> e->key >> e->data;
l.insertFront( e );
break;
case INSERTREAR: e = new NODE; // insert at rear
cout << "Enter key and data : " << flush;
cin >> e->key >> e->data;
l.insertEnd( e );
break;
case INSERTSORTED:e = new NODE; // insert sorted by key
cout << "Enter key and data : " << flush;
cin >> e->key >> e->data;
l.insertSorted( e );
break;
case REMOVEFRONT: e = l.getFirst(); // remove front element
if( e == NULL ) // unless list is empty...
{
cout << "Not found" << endl;
}
else
{
cout << "key " << e->key << ", data " << e->data << endl;
delete e;
}
break;
case REMOVEREAR: e = l.getLast(); // remove last element
if( e == NULL )
{
cout << "Not found" << endl;
}
else
{
cout << "key " << e->key << ", data " << e->data << endl;
delete e;
}
break;
case REMOVEBYKEY: cout << "Enter key : " << flush; // remove an element by key
cin >> key;
e = l.getNode( key );
if( e == NULL )
{
cout << "Not found" << endl;
}
else
{
cout << "key " << e->key << ", data " << e->data << endl;
delete e;
}
break;
case PRINTALL: cout << "-------------------------" << endl; // print the list
l.printAll();
cout << "-------------------------" << endl;
break;
case HOWMANY: cout << "LIST has " << l.getCount() << " elements\n"; // count
case QUIT: break;
default: cout << "I don't understand, sorry...\n" << flush;
}
}
return 0;
}