Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct nod
  6. {
  7. int info;
  8. nod *leg;
  9. };
  10.  
  11. int n;
  12.  
  13. nod *creare ()
  14. {
  15. nod *prim, *p, *q, *n;
  16. prim = new nod;
  17. cin >> prim->info;
  18. q=prim;
  19. while (q -> info != 0)
  20. {
  21. p = new nod;
  22. cin >> p-> info;
  23. q->leg=p;
  24. n = q;
  25. q=p;
  26. }
  27. n -> leg = NULL;
  28. return prim;
  29. }
  30.  
  31. void parcurgere(nod *prim)
  32. {
  33. nod *p;
  34. p = prim;
  35. while (p)
  36. {
  37. cout << p -> info << " ";
  38. p = p -> leg;
  39. }
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45. int k;
  46. nod *prim;
  47. prim = creare();
  48. for(nod *p = prim; p != NULL; p = p -> leg)
  49. {
  50. n++;
  51. }
  52. cout << "Pe ce pozitie se face inserarea?";
  53. cin >> k;
  54. cin p -> inf;
  55. inserare (prim, k, inf);
  56. parcurgere(prim);
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement