Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("atestat.in");
  5. struct nod
  6. {
  7. int info;
  8. nod *urm, *ant;
  9. }*p, *q, *prim, *ultim;
  10. int x,s;
  11. void citire()
  12. {
  13. prim=NULL;
  14. while(fin>>x)
  15. {
  16. p=new nod;
  17. p->info=x;
  18. p->urm=NULL;
  19. if(prim==NULL)
  20. {
  21. prim=p;
  22. p->ant=NULL;
  23. ultim=p;
  24. }
  25. else
  26. {
  27. ultim->urm=p;
  28. p->ant=ultim;
  29. ultim=p;
  30. }
  31. s=s+x;
  32. }
  33. }
  34. void tip()
  35. {
  36. p=prim;
  37. while(p!=NULL)
  38. {
  39. cout<<p->info<<" ";
  40. p=p->urm;
  41. }
  42. cout<<"\n";
  43. }
  44. void tip2()
  45. {
  46. p=ultim;
  47. while(p!=NULL)
  48. {
  49. cout<<p->info<<" ";
  50. p=p->ant;
  51. }
  52. cout<<"\n";
  53. }
  54. void rez()
  55. {
  56. q=new nod;
  57. q->info=s;
  58. q->urm=prim;
  59. q->ant=NULL;
  60. prim=q;
  61. }
  62. int main()
  63. {
  64. citire();
  65. tip2();
  66. rez();
  67. tip();
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement