Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zad2 14/15
- #include <iostream>
- using namespace std;
- struct node {
- int val;
- node *next;
- };
- struct TwoLists {
- node *odd;
- node *even;
- };
- void _CreateList ( node *&first);//tworzy listê
- void _CoutList (node *first);//wypisuje listê
- bool Odd (int val){
- if(val&1==1) return true;
- else return false;
- }
- TwoLists split (node *list){
- node *head_odd=NULL;
- node *head_even=NULL;
- node *prev=NULL;
- while (list!=NULL){
- prev=list;
- list=list->next;
- if(Odd(prev->val)==true){
- prev->next=head_odd;
- head_odd=prev;
- }
- else{
- prev->next=head_even;
- head_even=prev;
- }
- }
- TwoLists res;
- res.even=head_even;
- res.odd=head_odd;
- return res;
- }
- int main()
- {
- node *h=NULL;
- _CreateList(h);
- TwoLists res=split(h);
- _CoutList(res.even);
- cout<<endl;
- _CoutList(res.odd);
- return 0;
- }
- void _CreateList ( node *&first){
- int len;
- cin>>len;
- node *p;
- for(int i=0;i<len;i++){
- int x;
- cin>>x;
- p= new node;
- p->val=x;
- p->next=first;
- first=p;
- }
- }
- void _CoutList (node *first){
- while ( first !=NULL)
- {
- cout<<first->val<<" ";
- first=first->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement