/*2018.11
*数据结构与算法-第8章习题T3算法设计题
*(4)编写算法,对n个关键字取整数值的记录序列进行整理,以使所有关键字为负值的记录排在关键字为非负值的记录之前
*要求:1.采用顺序存储结构,至多使用一个记录的辅助存储空间;
2.算法的时间复杂度为o(n)(即使用快速排序)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef int elemtype;
typedef struct
{
elemtype *elem;
int length;
}Sqlist;
void initList(Sqlist &list,int n)/*创建顺序存储数组*/
{
list.elem=new int[n+1];
if(!list.elem)
return;
list.length=n;
}
void ListInsert(Sqlist &list,int i,int num)/*插入数据*/
{
if(i<1)return;
list.elem[i]=num;
}
void outputList(Sqlist list)/*输出顺序存储的数组*/
{
for(int i=1;i<=list.length;i++)
{
printf("%4d",list.elem[i]);
if(i%10==0)
printf("\n");
}
printf("\n");
}
int partition(Sqlist &list,int low,int high)/*排序函数1*/
{
elemtype temp;
list.elem[0]=list.elem[low];
temp=list.elem[low];
while(low<high)
{
while(low<high && list.elem[high]>=temp)
--high;
list.elem[low]=list.elem[high];
while(low<high && list.e