题目:已知带头结点单链表L,设计算法实现:以表中第一个元素作为标准,将表中所有值小于第一个元素 的结点均放在第一个结点之前 ,所有值大于 第一个元素的结点均放在第一个元素结点之后。
这是一个强行分类的方式……
#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
Node *next;
};
//合并
Node* connect(Node* big, Node* small, int count, int num){
Node* r, *ans;
ans = (Node*)malloc(sizeof(Node));
r = (Node*)malloc(sizeof(Node));
ans->next=NULL;
//头插法
r = big->next;
while(r!=NULL){
Node* s = (Node*)malloc(sizeof(Node));
s->data = r->data;
s->next = ans->next;
ans->next = s;
r = r->next;
}
for(int i=0; i<count; i++