Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "linkedListType.h"
- using namespace std;
- linkedListType* Merge(linkedListType *ln,linkedListType *ln2){
- linkedListType *temp = new linkedListType();
- if(ln2->listSize()==ln->listSize()){
- for(int i=0;i<ln->listSize();i++){
- temp->insertEnd(ln->getItem(i));
- temp->insertEnd(ln2->getItem(i));
- }
- }else if(ln2->listSize()>ln->listSize()){
- for(int i=0;i<ln->listSize();i++){
- temp->insertEnd(ln->getItem(i));
- temp->insertEnd(ln2->getItem(i));
- }
- for(int i=ln->listSize();i<ln2->listSize();i++)
- temp->insertEnd(ln2->getItem(i));
- }else if(ln->listSize()>ln2->listSize()){
- for(int i=0;i<ln2->listSize();i++){
- temp->insertEnd(ln->getItem(i));
- temp->insertEnd(ln2->getItem(i));
- }
- for(int i=ln2->listSize();i<ln->listSize();i++)
- temp->insertEnd(ln->getItem(i));
- }
- // ln->clearList();
- // ln2->clearList();
- return temp;
- }
- int main(){
- linkedListType *ln = new linkedListType();
- linkedListType *ln2 = new linkedListType();
- linkedListType *ln3 = new linkedListType();
- ln->insertEnd(1);
- ln2->insertEnd(2);
- ln->insertEnd(3);
- ln2->insertEnd(4);
- ln->insertEnd(5);
- ln2->insertEnd(6);
- ln2->insertEnd(7);
- ln3=Merge(ln,ln2);
- ln3->print();
- ln->Merge(ln2);
- ln->print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement