Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Sada napravimo modifikaciju prethodnog primjera
- tako da se podaci spremaju redoslijedom kojim se
- unose (0 je na kraju liste).*/
- #include <iostream>
- using namespace std;
- struct node
- {
- int data;
- node *link;
- };
- void write(node *head);
- void input(node *&head, int elt);
- int main()
- {
- int x;
- node *head=0;
- do{
- cin>>x;
- input(head,x);
- }while(x!=0);
- write(head);
- return 0;
- }
- void write(node *head)
- {
- while(head) // MOŽE I: while(head!=0)
- {
- cout<<head->data<<" ";
- head=head->link;
- }
- }
- void input(node *&head, int elt)
- {
- node *current=new node;
- current->data=elt;
- current->link=0;
- if(head==0)
- {
- head=current;
- }
- else
- {
- node *temp=head;
- while(temp->link)
- temp=temp->link;
- temp->link=current;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement