Advertisement
NAEGAKURE

povezane liste pr 2

Apr 26th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. /*Napravimo modifikaciju u prethodnom primjeru
  2. tako da unos elemenata bude implementiran u
  3. posebnoj funkciji*/
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. struct node
  9. {
  10.     int data;
  11.     node *link;
  12.  
  13. };
  14.  
  15. void write(node *head);
  16. void input(node *&head, int elt);
  17.  
  18. int main()
  19. {
  20.     int x;
  21.     node *head=0;
  22.     do{
  23.             cin>>x;
  24.             input(head,x);
  25.  
  26.     }while(x!=0);
  27.  
  28.     write(head);
  29.  
  30.  
  31.     return 0;
  32. }
  33.  
  34. void write(node *head)
  35. {
  36.     while(head) // MOŽE I: while(head!=0)
  37.     {
  38.         cout<<head->data<<" ";
  39.         head=head->link;
  40.     }
  41. }
  42.  
  43. void input(node *&head, int elt)
  44. {
  45.     node *current=new node;
  46.     current->data=elt;
  47.     current->link=head; //pokazuje na pocetak liste
  48.     head=current;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement