Created
April 20, 2015 21:24
-
-
Save songpu2015617/0edc83a050898168f58b to your computer and use it in GitHub Desktop.
cc150 2.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
node *partitionlist(node *head, int x){ | |
node *dummy = new node(); | |
dummy->next=head; | |
head=dummy; | |
node *last=head; | |
int len=0; | |
if (head==NULL) return NULL; | |
if (head->next==NULL) return head; | |
while (last->next!=NULL) { | |
last=last->next; | |
++len; | |
} | |
while (len>0){ | |
if (dummy->next->data >x ){ | |
node *q= dummy->next; | |
dummy->next=dummy->next->next; | |
dummy=dummy->next; | |
last->next=q; | |
q->next=NULL; | |
last=last->next; | |
} | |
else { | |
dummy=dummy->next; | |
} | |
len--; | |
} | |
return head->next; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment