Advertisement
bratishkaaa

Untitled

Mar 25th, 2020
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. Для заданной структуры написать функции и вызвать их последовательно в теле функции main:
  2.  
  3. include"stdafx.h"
  4. #include<iostream>
  5. #include<fstream>
  6. usingnamespacestd;
  7.  
  8. structloop {
  9.     int data;
  10.     loop* next;
  11.     loop* prev;
  12. };
  13.  
  14. voidsaveforward(loop* ploop, fstream&file)
  15. {
  16.     if (ploop)
  17.     {
  18.         loop * temp = ploop;
  19.         do {
  20.             file<<ploop->data <<" ";
  21.             ploop = ploop->next;
  22.         } while (ploop != temp);
  23.     }
  24.    
  25. }
  26.  
  27. voidsavebackward(loop* ploop, fstream&file)
  28. {
  29.     if (ploop)
  30.     {
  31.         loop * temp = ploop;
  32.         do {
  33.             file<<ploop->data <<" ";
  34.             ploop = ploop->prev;
  35.         } while (ploop != temp);
  36.     }
  37.  
  38. }
  39.  
  40. intmain()
  41. {
  42.     inti;
  43.     fstream file1;
  44.     file1.open("output.txt", fstream::out);
  45.     file1.clear();
  46.  
  47.     loop* pl1=newloop;
  48.     pl1->next = pl1;
  49.     pl1->prev = pl1;
  50.     pl1->data = 0;
  51.    
  52.    
  53.     saveforward(pl1, file1);
  54.     file1 <<endl;
  55.  
  56.     savebackward(pl1, file1);
  57.     file1 <<endl;
  58.    
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement