Advertisement
czlowiek-sendor

Untitled

Mar 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. struct Node
  7. {
  8. Node * next;
  9. int data;
  10. };
  11.  
  12. unsigned l_size(Node * p)
  13. {
  14. unsigned c = 0;
  15.  
  16. while (p)
  17. {
  18. c++;
  19. p = p->next;
  20. }
  21. return c;
  22. }
  23.  
  24. // Procedura wyświetla zawartość elementów listy
  25. void l_printl(Node * p)
  26. {
  27. unsigned i;
  28.  
  29. for (i = 1; p; p = p->next)
  30. cout << "Element #" << i++ << " data = " << p->data << endl;
  31. cout << endl;
  32. }
  33.  
  34. void l_push_front(Node * & head, int v)
  35. {
  36. Node * p;
  37.  
  38. p = new Node;
  39. p->data = v;
  40. p->next = head;
  41. head = p;
  42. }
  43.  
  44. // Procedura usuwa pierwszy element
  45. void l_pop_front(Node * & head)
  46. {
  47. Node * p = head;
  48.  
  49. if (p)
  50. {
  51. head = p->next;
  52. delete p;
  53. }
  54. }
  55.  
  56.  
  57. int main()
  58. {
  59. Node * L = NULL;
  60. for (int i = 0; i < 10; i++) {
  61.  
  62. l_push_front(L, i);
  63. }
  64. l_printl(L);
  65.  
  66. system("pause");
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement