一、sort 线性表
#include <stdio.h>
#include "SequenceList.h"
#include "SequenceList.h"
void visit(DataType e)
{
printf("%d ", e);
}
{
printf("%d ", e);
}
int Large(DataType a, DataType b)
{
return (a > b) ? 0 : 1;
}
{
return (a > b) ? 0 : 1;
}
int main()
{
int ret, i, num;
List list;
{
int ret, i, num;
List list;
ret = InitSequence(&list);
if (FAILURE == ret)
if (FAILURE == ret)
{
printf("Init Failure!\n");
}
printf("Init Failure!\n");
}
printf("Please input ten numbers :\n");
for (i = 0; i < SIZE; i++)
{
scanf("%d", &num);
{
scanf("%d", &num);
ret = LocateElem(list, num, Large);
if (FAILURE == ret)
{
InsertSequence(&list, list.length + 1, num);
}
else
{
InsertSequence(&list, ret, num);
}
if (FAILURE == ret)
{
InsertSequence(&list, list.length + 1, num);
}
else
{
InsertSequence(&list, ret, num);
}
}
TraverseSequence(list, visit);
printf("\n");
return 0;
}
}
二、链式栈sort
#include <stdio.h>
#include "LinkStack.h"
#include "LinkStack.h"
#define SIZE 10
int main()
{
int a;
Stack *num, *tmp;
int i;
{
int a;
Stack *num, *tmp;
int i;
if (InitStack(&num) != SUCCESS || InitStack(&tmp) != SUCCESS)
{
printf("Init Failure!\n");
}
{
printf("Init Failure!\n");
}
printf("Please input :\n");
for (i = 0; i < SIZE; i++)
{
scanf("%d", &a);
{
scanf("%d", &a);
while (EmptyStack(num) != SUCCESS && a <= GetTop(num))
{
Push(tmp, Pop(num));
}
Push(num, a);
while (EmptyStack(tmp) != SUCCESS)
{
Push(num, Pop(tmp));
}
}
{
Push(tmp, Pop(num));
}
Push(num, a);
while (EmptyStack(tmp) != SUCCESS)
{
Push(num, Pop(tmp));
}
}
while (EmptyStack(num) != SUCCESS)
{
printf("%d ", Pop(num));
}
printf("\n");
{
printf("%d ", Pop(num));
}
printf("\n");
return 0;
}
}