Pregled posta

Adresa bloga: https://blog.dnevnik.hr/prirodaa

Marketing

kol,2liste -parni stog,nep red

#include
#include
using namespace std;

struct node{
int data;
node *link;
};

void unos(node *&,node*&,node*&,node*&);
void ispis(node *);
void elt_u_red(node*&,node*&,int);
void elt_u_stog(node*&,int);
void test(node*,node*);

int main()

{ node *head=0,*head1=0,*last=0,*top=0;
unos(head,head1,last,top);

cout<<"\nispis unesenog niza: ";
ispis(head);

cout<<"\nispis stoga: ";
ispis(top);

cout<<"\nispis reda: ";
ispis(head1);

test(head1,top);
node *curr=head,*temp;
while(curr)
{
temp=curr;
curr=curr->link;
delete temp;
}
while(top)
{
curr=top;
top=top->link;
delete curr;
}
while(head1)

{
curr=head1;
head1=head1->link;
delete curr;
}
last=0;
curr=0;
cin.sync();
cin.get();
return 0;
}
void test(node *head1,node *top)

{
int n,m,a1=0,a2=0;
while(head1 && top)
{
n=head1->data;
head1=head1->link;
m=top->data;
top=top->link;
if(-n >m)
a1++;
else
a2++;
}

if(head1==0)
cout<<"pobjednik je stog!";
else if(top==0)
cout<<"pobjednik je red!";
else if(a1>a2)
cout<<"povjednik je red!";
else
cout<<"pobjednik je stog!";

}
void unos(node *&head,node*&head1,node*&last,node*&top)
{
int n;
do{
cout<<"Unesi broj: ";
cin>>n;
node *curr=new node;
curr->data=n;
curr->link=head;
head=curr;
if(n<0)
elt_u_red(head1,last,n);
else if(n>0)
elt_u_stog(top,n);
}while(n!=0);

}
void elt_u_stog(node *&top,int n)
{ node *curr=new node;
curr->data=n;
curr->link=top;
top=curr;
}

void elt_u_red(node *&head1,node *&last,int n)
{ node *curr=new node;
curr->data=n;
curr->link=0;
if (head1==0) head1=curr;
else last->link=curr;
last=curr;
}
void ispis(node *head)
{
if(head)
{
node *curr=head;
while(curr)

{ cout<data<<" ";
curr=curr->link;

} }}








Post je objavljen 05.06.2012. u 10:40 sati.