本文整理汇总了C++中List::Delete方法的典型用法代码示例。如果您正苦于以下问题:C++ List::Delete方法的具体用法?C++ List::Delete怎么用?C++ List::Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List::Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2:
TEST(List, can_delete) { //
List<int> list;
list.AddToHead(1);
list.AddToHead(2);//2,1
list.AddElementOrdered(3);
ASSERT_NO_THROW(list.Delete());
}
示例3: main
// Тестовый пример
void main()
{
// Создаем объект класса List
List lst;
// Тестовая строка
char s[] = "Hello, World !!!\n";
// Выводим строку
cout << s << "\n\n";
// Определяем длину строки
int len = strlen(s);
// Загоняем строку в список
for(int i = 0; i < len; i++)
lst.Add(s[i]);
// Распечатываем содержимое списка
lst.Print();
// Удаляем три элемента списка
lst.Del();
lst.Del();
lst.Del();
//Распечатываем содержимое списка
lst.Print();
//Вставляем 3-й символ, согласно нумерации массива с нуля
lst.Insert('+',2);
lst.Print();
//удаляем 3-й символ
lst.Delete(2);
lst.Print();
//находим позицию элемента 'l'
cout<<"First position of 'l': "<<lst.Search('l')<<endl<<endl;
}
示例4: test
void test(){
List * Head = new List(2);
Head->Insert(2);
Head->Insert(2);
Head->Insert(15);
Head->Insert(7);
Head->Insert(15);
Head->Insert(5);
Head->Insert(5);
Head->Print();
Head->Delete(5);
Head->Delete(5);
Head->Delete(5);
Head->Delete(7);
Head->Print();
}
示例5: Concat
//------------------------------------------------------------------------------
//Функция объединения двух упорядоченных списков с сохранением порядка
List Concat(List list1,List list2)
{
if (list1.root==NULL || list2.root==NULL)
{
cout <<"Concat2:error: one or more lists is empty\n";
}
TNode *temp1,*temp2;
temp1=list1.last;
temp2=list2.root;
while (temp2!=NULL)
{
for (;;)
{
if ( (temp1->data < temp2->data) || (temp1->prev==NULL) ) break;
temp1=temp1->prev;
}
if ( (temp1==list1.root) && (temp1->data > temp2->data) )
list1.AddBefore(temp1,temp2->data);
else
list1.AddAfter(temp1,temp2->data);
temp1=list1.last;
if (temp2->next==NULL) break;
temp2=temp2->next;
list2.Delete(list2.root);
}
return list1;
}
示例6: 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;
}
示例7: refresh_processes
void refresh_processes ( List &black_list , List &black_list_checks , List &processes )
{
unsigned int cont;
/* Walking the list */
for ( cont = 0 ; cont < black_list.Len () ; cont ++ )
{
/* If the process DIED */
if ( processes.Find ( black_list.Get ( cont ) ) == FALSE )
{
/* Deleting this OLD PID */
black_list.Delete ( cont );
black_list_checks.Delete ( cont );
/* Compensating the element extraction */
cont --;
}
}
}
示例8: ListUnitTest
bool ListUnitTest()
{
List *t = new List();
List *s = NULL;
List *u = NULL;
List::Add(&t, new List());
List::Add(&t, new List());
List::Add(&t, new List());
t->Delete(&t);
t->Delete(&t);
t->Delete(&t);
List::Add(&t, new List());
List::Add(&t, new List());
s = t->head->Extract();
u = t->tail->Extract();
return true;
}
示例9: main
void main()
{
List t;
int n;
do{
cout<<"\n***********************主菜单*****************************";
cout<<"\n\n************** 1.增加城市; *******************";
cout<<"\n\n************** 2.删除城市; *******************";
cout<<"\n\n************** 3.查询城市信息; *******************";
cout<<"\n\n************** 4.修改城市信息; *******************";
cout<<"\n\n************** 5.查询某坐标附近的城市;*******************";
cout<<"\n\n************** 6.其他按键退出程序; *******************";
cout<<"\n\n**********************************************************"<<endl;
cout<<"\n请输入你的选择操作:";
cin>>n;
switch(n) {
case 1:
t.Insert();//1.增加城市
cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
_getch();
cout<<"\n";
break;
case 2:
t.Delete(); //2.删除城市
cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
_getch();
cout<<"\n";
break;
case 3:
t.Search(); //3.查询城市信息
cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
_getch();
cout<<"\n";
break;
case 4:
t.Change();//4.修改城市信息
cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
_getch();
cout<<"\n";
break;
case 5:
t.Nearcity();//5.查询某点附近的城市
cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
_getch();
cout<<"\n";
break;
default:
break; //6.其他按键退出程序
}
}while(n>0&&n<6);
}
示例10: main
int main()
{
List<int> list;
for(int i=0;i<10;i++) list.Insert(i+1,i*(1+i));
int a[10],b[10];
for(int i=0;i<list.Length();i++) cout<<list.GetElem(1+i,a[i])<<endl;
cout<<list.Length()<<endl;
cout<<list.LocateElem(90)<<endl;
list.NextElem(0,b[0]);
cout<<b[0]<<endl;
cout<<list.Delete(4,b[1])<<endl;
for(int i=0;i<list.Length();i++) cout<<list.GetElem(1+i,a[i])<<endl;
return 0;
}
示例11: menu
void menu(){
List * intList = new List;
int choice=0;
enum menuChoices {PRINT, INSERT, DELETE, EXIT};
cout << "Lab exercise for Chapter 6 Lists" << endl;
while(choice!=4){
cout << "Please pick from the following options:" << endl;
cout << "[1] Print current list" << endl;
cout << "[2] Insert integer to list" << endl;
cout << "[3] Delete integer from list" << endl;
cout << "[4] Exit" << endl << endl;
choice = getInt();
cout << endl;
switch(choice-1){
case PRINT:
intList->Print();
break;
case INSERT:
int newInt;
cout << "Enter the new integer to be added" << endl << endl;
newInt = getInt();
cout << endl;
intList->Insert(newInt);
break;
case DELETE:
int tarInt;
cout << "Enter the integer to be deleted" << endl << endl;
tarInt = getInt();
cout << endl;
intList->Delete(tarInt);
break;
case EXIT:
cout << "Goodbye." << endl << endl;
delete intList;
break;
default:
cout << "Please enter a valid option." << endl << endl;
}
}
}
示例12: WillAccept
int GWindow::WillAccept(List<char> &Formats, GdcPt2 Pt, int KeyState)
{
int Status = DROPEFFECT_NONE;
for (char *f=Formats.First(); f; )
{
if (stricmp(f, LGI_FileDropFormat) == 0)
{
f = Formats.Next();
Status = DROPEFFECT_COPY;
}
else
{
Formats.Delete(f);
DeleteArray(f);
f = Formats.Current();
}
}
return Status;
}
示例13: main
int main(){
//read("in.txt");
List l;
int x,c;
do{
c = prompt();
switch(c){
case 1:
cout << "Please, Enter the number to be Inserted : \n";
cin >> x;
l.Insert(x);
break;
case 2:
cout << "Please, Enter the number to be Deleted : \n";
cin >> x;
x = l.Delete(x);
if (x == -1)
cout << "Element not found!\n";
break;
case 3:
l.Print();
cout << "\n";
break;
case 4:
l.PrintRev();
cout << "\n";
break;
case 5:
cout << "Please, Enter the index of the element to be swapped with it's successor : \n";
cin >> x;
l.Swap(x);
break;
case 6:
l.Reverse();
break;
default:
return 0;
}
}while(c < 7);
}
示例14:
void operator delete[](void* p)throw()
{
if(p == NULL) return;
MemManager.Delete(Node(reinterpret_cast<long>(p)));
free(p);
}
示例15: main
int main(){
// New list
List list;
Node *answer;
// Add_End nodes to the list
list.Add_End(111);
list.Print();
list.Add_End(222);
list.Print();
list.Add_End(333);
list.Print();
list.Add_End(444);
list.Print();
list.Add_End(555);
list.Print();
cout << endl << endl;
// Delete nodes from the list
list.Delete(444);
list.Print();
// list.Delete(333);
// list.Print();
// list.Delete(222);
// list.Print();
// list.Delete(555);
// list.Print();
// list.Delete(111);
// list.Print();
// cout<<endl<<endl;
//
// cout << "Testing Add_Front: and others"<<endl;
// list.Add_Front(888);
// list.Print();
// list.Add_Front(999);
// list.Print();
// list.Add_Front(49);
// list.Print();
// cout<<endl<<endl;
// cout << "Checking find function"<<endl;
// answer = list.Find(888);
// cout<<"Value for node returned by find function call with 888 is "<<answer->Data()<<"."<<endl;
// cout<<"Checking find function"<<endl;
// answer = list.Find(999);
// cout<<"Value for node returned by find function call with 888 is "<<answer->Data()<<"."<<endl;
//
// cout<<"Checking find function"<<endl;
// answer = list.Find(49);
// cout<<"Value for node returned by find function call with 888 is "<<answer->Data()<<"."<<endl;
// cout<<"Call find function with value not in list."<<endl;
// answer = list.Find(7);
// if(answer == NULL)
// {
// cout<<"returned null pointer since 7 not found"<<endl;
//
// }
// else
// {
// cout<< "in else of answer == NULL where Value for node returned by find function call with 7 is "<<answer->Data()<<"."<<endl;
// }
//
// cout<<"testing delete_front: "<<endl;
// list.Delete_Front();
// list.Print();
// cout<<"testing delete_end: "<<endl;
//
// list.Delete_End();
// list.Print();
return 0;
}