Advertisement
edutedu

liste fisiere

Oct 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream f("text.in");
  6.  
  7. struct nod
  8. {
  9. int info;
  10. nod*leg;
  11. };
  12.  
  13. nod* creare(int n)
  14. {
  15. nod *prim, *p, *q;
  16. prim=new nod;
  17. q=prim;
  18. cout<<"Introduceti informatia din nodul 1 : ";
  19. f>>prim->info;
  20. for(int i=2; i<=n; i++)
  21. {
  22. p=new nod;;
  23. cout<<"Introduceti informatia din nodul "<<i<<" : ";
  24. f>>p->info;
  25. q->leg=p;
  26. q=p;
  27. }
  28. p->leg=NULL;
  29. return prim;
  30. }
  31.  
  32. void parcurgere(nod *prim)
  33. {
  34. nod*p;
  35. p=prim;
  36. while(p)
  37. {
  38. cout<<p->info<<" ";
  39. p=p->leg;
  40. }
  41. }
  42.  
  43. int main()
  44. {
  45. nod *prim;
  46. int n;
  47. cout<<"Cate elemente are lista? "; f>>n;
  48. prim=creare(n);
  49. parcurgere(prim);
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement