链表插入排序

void insertsort(List &SortAsCount,Node * node)
{
Node *q = new Node;
q->count = node->count;
q->data = node->data;
q->len = node->len ;
if(SortAsCount.first == NULL)
SortAsCount.first = q;
else{
if(q->len <= SortAsCount.first->len ){
q->next = SortAsCount.first;
SortAsCount.first = q;
}
else{
Node *p_prior,*p = SortAsCount.first;


while(p != NULL && q->len > p->len ){
p_prior = p;
p = p->next;
}
p_prior->next = q;
q->next = p;
}


}

}


int SortWithInsetMethod(List &SortAsData)
{
unsigned int countword(0);
for(int i = 0 ; i <Arr_Length ; i++){
Node *p = MyList[i].getfirst();
p = p->next;
while(p){
if(p->count == 0){
p = p->next;
continue;
}
wchar *pp = p->data;
/*if(isNum(*pp)){
p = p->next;
continue;

}*/
int i = 0;
i = p->count ;
insertsort(SortAsData,p);
countword = countword + p->count;
p = p->next;
 
} 
}


printf("%s%d\n","the number of words is :",countword);
return countword;


}


你可能感兴趣的:(链表插入排序)