Advertisement
Guest User

Untitled

a guest
May 24th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("date.in");
  5. ofstream fout("date.out");
  6. struct nod{
  7. int inf;
  8. nod *urm,*ant;
  9. };
  10. void adaugare(nod *&ultim,nod *&prim,int x)
  11. {
  12. nod *p=new nod;
  13. p->inf=x;
  14. p->urm=NULL;
  15. if(prim==NULL)
  16. {
  17. p->ant=NULL;
  18. prim=ultim=p;
  19. }
  20. else
  21. {
  22. p->ant=ultim;
  23. ultim->urm=p;
  24. ultim=p;
  25. }
  26. }
  27. void creare(nod *&prim,nod *&ultim)
  28. {
  29. int x;
  30. prim=NULL;
  31. while(fin>>x)
  32. adaugare(ultim,prim,x);
  33. }
  34. void afisare(nod *p)
  35. {
  36. while(p!=NULL)
  37. {
  38. fout<<p->inf<<" ";
  39. p=p->urm;
  40. }
  41. }
  42.  
  43. int main()
  44. {
  45. nod *prim,*ultim;
  46. creare(prim,ultim);
  47. afisare(prim);
  48.  
  49.  
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement