Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct ll {
  5. int value;
  6. ll* next;
  7. };
  8.  
  9. ll* root = NULL;
  10. ll* root1 = NULL;
  11. ll* root2 = NULL;
  12. ll* current = NULL;
  13. ll* tmp;
  14.  
  15. void insert(ll* lroot, int value){
  16. if (lroot == NULL){
  17. lroot = new ll;
  18. lroot->value = value;
  19. lroot->next = NULL;
  20. current = lroot;
  21. return;
  22. }
  23. tmp = new ll;
  24. tmp->value = value;
  25. tmp->next = NULL;
  26. current->next = tmp;
  27. current = tmp;
  28. return;
  29. }
  30.  
  31. void print(ll* lroot){
  32. current = lroot;
  33. while (current != NULL) {
  34. cout << current->value << " -> ";
  35. current = current->next;
  36. }
  37. cout << "NULL\n";
  38. return;
  39. }
  40.  
  41. void readll(ll* lroot){
  42. int value;
  43. while (1) {
  44. cin >> value;
  45. if (!value) break;
  46. insert(lroot, value);
  47. }
  48. print(lroot);
  49. return;
  50. }
  51. int main() {
  52. readll(root1);
  53. readll(root2);
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement