5-22.c

来自「数据结构经典算法」· C语言 代码 · 共 39 行

C
39
字号
#include "stdio.h"
typedef int datatype;
typedef	  struct	node{
	datatype	  data;/*数据内容*/
	int		key;/*关键字*/
	struct 	node  *next;
} listnode;
typedef int Arrtype ;
listnode * binsort(Arrtype  A[],int arr_num)
{	/*A要排序的数组,arr_num为数组大小*/
	listnode *head,*q,*temp;
	int i;
	head=(listnode *)malloc(sizeof(listnode ));
	head->key=-1;/*便于后面的比较*/
	head->next=NULL;
	i=0;
	for(i;i<arr_num;i++)
	{
		q=head->next;
		while(q)
		{/*找到插入入口,插入结点*/
			if((q->key<A[i])&&((q->next==NULL)||(q->next->key>A[i])))
			{
				temp=(listnode*)malloc(sizeof(listnode));
				temp->data=A[i];
				temp->key=A[i];
				temp->next=q->next;
				q->next=temp;
			}
		}
	}
	return(head);
}

void main()
{
	int  c[10];
	listnode *node=binsort(c,10);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?