Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Node
- {
- int data;
- struct Node *next;
- }
- struct Node* function(struct Node *a,struct Node *b)
- {
- struct Node *result=NULL;
- if(a==NULL)
- return b;
- else if(b==NULL)
- return a;
- if(a−>data<=b−>data)
- {
- result=a;
- result−>next=function(a−>next,b);
- }
- else
- {
- result=b;
- result−>next=function(a,b−>next);
- }
- return result;
- }
- // Wersja iteracyjna z użyciem stosu:
- // (trochę pseudo-kod, bo stosu tu nie implementowałem)
- struct Node* function(struct Node *a,struct Node *b)
- {
- Stack<struct Node *> stack;
- struct Node *result;
- struct Node *oldResult;
- while(a && b)
- {
- if(a->data <= b->data)
- {
- stack.push(a);
- a=a->next;
- }
- else
- {
- stack.push(b);
- b=b->next;
- }
- }
- result= a ? a : b;
- while(!stack.empty())
- {
- oldResult=result;
- result=stack.pop();
- result->next=oldResult;
- }
- return result;
- }
Add Comment
Please, Sign In to add comment