Advertisement
Guest User

Spiski

a guest
May 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5.  
  6. struct List{
  7.     int value;
  8.     List *next;    
  9. };
  10.  
  11.  
  12. void DeleteList(){
  13.    
  14. }
  15. void PrintList(List **begin){
  16.     List *tmp = (*begin);
  17.     cout << "\n";
  18.     while(tmp){      
  19.         cout << tmp->value << " -> ";
  20.         tmp = tmp->next;
  21.     }
  22. }
  23.  
  24. void InitList(List **node, int count){        
  25.     (*node) = new List;
  26.     (*node)->next = NULL;    
  27.     List *tmp = *node;
  28.        
  29.     cout << "\nVvedite element: ";
  30.     cin >> tmp->value;
  31.     for(int i=1;i<count;i++){
  32.         tmp->next = new List;
  33.         tmp = tmp->next;
  34.         cout << "\nVvedite element: ";
  35.         cin >> tmp->value;        
  36.         tmp->next = NULL;
  37.     }
  38. }
  39.  
  40. int main() {
  41.    
  42.     List *head_1 = new List;    
  43.     head_1->next = NULL;
  44.     int count;
  45.     cout << " Vvedite kolichestvo elementov\n";
  46.     cin >> count;    
  47.     InitList(&head_1,count);
  48.     List *head_2 = new List;
  49.     List *tmp1 = head_1;    
  50.     List *tmp2 = head_2;
  51.     int number_of_node;
  52.     do{
  53.         cout << "\nVvedite chislo dla vtorovo spiska: ";
  54.         cin >> number_of_node;
  55.     }while((number_of_node < 0) || (number_of_node > count));
  56.        
  57.     for(int i=0;i<number_of_node-1;i++){
  58.         tmp1 = tmp1->next;
  59.     }
  60.    
  61.     tmp2->value = tmp1->value;    
  62.     tmp1 = tmp1->next;                                
  63.     while(tmp1){        
  64.         tmp2->next = new List;
  65.         tmp2 = tmp2->next;
  66.         tmp2->value = tmp1->value;                
  67.         tmp1 = tmp1->next;                                
  68.     }
  69.     PrintList(&head_2);
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement