Skip to content

Instantly share code, notes, and snippets.

@songpu2015617
Created April 20, 2015 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save songpu2015617/0edc83a050898168f58b to your computer and use it in GitHub Desktop.
Save songpu2015617/0edc83a050898168f58b to your computer and use it in GitHub Desktop.
cc150 2.4
#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