#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<string.h>
#define MAX_SIZE 5
typedef int DataType;
typedef struct SeqList
{
size_t size;
DataType array[MAX_SIZE];
}SeqList;
//冒泡排序
//void swap(DataType *left, DataType *right)
//{
// DataType tmp = *left;
// *left = *right;
// *right = tmp;
//}
//
//void BubbleSort(SeqList* pSeq)
//{
// int i = 0;
// int j = 0;
// int flag = 0;
// assert(pSeq);
// for (i = 0; i < pSeq->size - 1; i++)
// {
// for (j = 1; j < pSeq->size - i; j++)
// {
// if (pSeq->array[j - 1]> pSeq->array[j])
// {
// swap(&pSeq->array[j - 1], &pSeq->array[j]);
// flag = 1;
// }
// }
// if (flag == 0)
// {
// return;
// }
// }
//}
//
//void Test1()
//{
// SeqList List;
// BubbleSort(&List);
//}
//
//int main()
//{
// Test1();
// system("pause");
// return 0;
//}
// 一次选出最大最小的数据分别放在序列的两端
//void SeclectSort(SeqList* pSeq)
//{
// int i, j;
// int min;
// assert(pSeq);
// for (j = 0; j < pSeq->size - 1; ++j)
// {
// min = j;
// for (i = j + 1; i < pSeq->size; ++i)
// {
// if (pSeq->array[min] > pSeq->array[i])
// {
// min = i;
// }
// }
// Swap(&pSeq->array[min], &pSeq->array[j]);
// }
//}
//
//void SeclectSort_OP(SeqList* pSeq)
//{
// int left = 0, right = pSeq->size - 1;
// int min, max, i;
// assert(pSeq);
//
// while (left < right)
// {
// for (i = left; i <= right; i++)
// {
// if (pSeq->array[i] < pSeq->array[left])
// {
// Swap(&pSeq->array[i], &pSeq->array[left]);
// }
//
// if (pSeq->array[i] > pSeq->array[right])
// {
// Swap(&pSeq->array[i], &pSeq->array[right]);
// }
// }
//
// ++left;
// --right;
// }
//}
//void Test2()
//{
// SeqList List;
// SeclectSort(&List);
// SeclectSort_OP(&List);
//}
//
//int main()
//{
// Test2();
// system("pause");
// return 0;
//}
//
//int BinarySearch(SeqList* pSeq, DataType x)
//{
// int left = 0;
// int right = pSeq->size;
// assert(pSeq);
// while (left <= right)
// {
// int mid = left - (left - right) / 2;
// if (x > pSeq->array[mid])
// {
// left = mid + 1;
// }
// else if (x < pSeq->array[mid])
// {
// right = mid - 1;
// }
// else
// {
// return mid;
// }
// }
// return -1;
//}
//
//void Test3()
//{
// SeqList List;
// BinarySearch(&List, 5);
//}
//int main()
//{
// Test3();
// system("pause");
// return 0;
//}
//void InitSeqList(SeqList* pSeq)
//{
// assert(pSeq);
// memset(pSeq->size, 0, sizeof(DataType)*MAX_SIZE);
// pSeq->size = 0;
//}
转载于:https://blog.51cto.com/10740184/1736246