spilt a list

spilt a list and become two sublists
void spilt(struct node *source, struct node** front, struct code** back){
    int len = count(source);
    int i;
    struct node* current =source;
    if(len<2)
    {
        *front = source;
        *back = null;
    }
    else
    {
        int partion=(len-1)/2;
        for(int i=0; i<partion; i++)
        {
            current=current->next;
        }
        //cut
        *front = source;
        *back=current->next;
        current->next = null;
    }
}

a little funtion is very useful in common. if you have more smarter code, please post it.

posted @ 2007-09-18 21:12  HonestMan  阅读(424)  评论(3编辑  收藏  举报