Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include "linkedListType.h"
  3.  
  4. using namespace std;
  5.  
  6. linkedListType* Merge(linkedListType *ln,linkedListType *ln2){
  7. linkedListType *temp = new linkedListType();
  8. if(ln2->listSize()==ln->listSize()){
  9. for(int i=0;i<ln->listSize();i++){
  10. temp->insertEnd(ln->getItem(i));
  11. temp->insertEnd(ln2->getItem(i));
  12. }
  13. }else if(ln2->listSize()>ln->listSize()){
  14. for(int i=0;i<ln->listSize();i++){
  15. temp->insertEnd(ln->getItem(i));
  16. temp->insertEnd(ln2->getItem(i));
  17. }
  18. for(int i=ln->listSize();i<ln2->listSize();i++)
  19. temp->insertEnd(ln2->getItem(i));
  20.  
  21. }else if(ln->listSize()>ln2->listSize()){
  22. for(int i=0;i<ln2->listSize();i++){
  23. temp->insertEnd(ln->getItem(i));
  24. temp->insertEnd(ln2->getItem(i));
  25. }
  26. for(int i=ln2->listSize();i<ln->listSize();i++)
  27. temp->insertEnd(ln->getItem(i));
  28.  
  29. }
  30. // ln->clearList();
  31. // ln2->clearList();
  32. return temp;
  33. }
  34.  
  35. int main(){
  36. linkedListType *ln = new linkedListType();
  37. linkedListType *ln2 = new linkedListType();
  38. linkedListType *ln3 = new linkedListType();
  39. ln->insertEnd(1);
  40. ln2->insertEnd(2);
  41. ln->insertEnd(3);
  42. ln2->insertEnd(4);
  43. ln->insertEnd(5);
  44. ln2->insertEnd(6);
  45. ln2->insertEnd(7);
  46. ln3=Merge(ln,ln2);
  47. ln3->print();
  48. ln->Merge(ln2);
  49. ln->print();
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement