Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //header
- public:
- UporList();
- UporList Merge(UporList A, UporList B);
- void OrderList();
- };
- //.cs
- UporList::UporList() : List()
- {
- top = new node;
- marker = top;
- }
- UporList UporList::Merge(UporList A, UporList B) {
- UporList C;
- C.Reset();
- for (node* tmp = A.top; tmp != NULL; tmp=tmp->next)
- {
- if (tmp->next == NULL)
- {
- break;
- }
- // cout<<"Debug: "<< tmp->data << "\n";
- C.Add(tmp->data);
- }
- for (node* tmp = B.top; tmp != NULL; tmp=tmp->next)
- {
- if (tmp->next == NULL)
- {
- break;
- }
- C.Add(tmp->data);
- }
- C.OrderList();
- return C;
- }
- void UporList::OrderList() {
- node *left = top;
- node *right = top->next;
- node *temp = new node;
- while (left->next){
- while (right)
- {
- if ((left->data) < (right->data)){
- temp->data = left->data;
- left->data = right->data;
- right->data = temp->data;
- }
- right = right->next;
- }
- left = left->next;
- right = left->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement