//------------------------------------------------------------------------------ //Функция объединения двух упорядоченных списков с сохранением порядка 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; }
void main(void) { List<int> data; data.PushBack(1); // 1 data.PopBack(); data.PopBack(); data.PopFront(); data.PushBack(2); // 2 data.PushBack(3); // 2 3 data.PushFront(-1); // -1 2 3 data.PushFront(-5); // -5 -1 2 3 data.PushBack(100); // -5 -1 2 3 100 data.Show(); cout << "Last TOP = " << data.Top() << endl; data.DelByVal(-5); //del like first data.DelByVal(100); //del like last cout << "first & last were deleted" << endl; data.Show(); // -1 2 3 int max = data.GetMaxEl(); cout << endl << "MAX element = " << max << endl; data.AddAfter(5,2); data.Show(); // -1 2 555 3 List<int> data2; data2 = data; cout << "Show data2 after operator = " << endl; data2.Show(); List<int> data3(data2); cout << "Show data3 after copy constructor " << endl; data3.Show(); //cout << "List after Sorting" << endl; //data3.SortBubble(); //data3.Show(); system("@pause"); }