Cocktailsort鸡尾酒排序

就是两边的冒泡排序, 和普通的冒泡排序一样通过不停的swap从队列中选择最值(最大or最小)的元素放到两侧. 一直持续这个操作直到最后.

#include <iostream>
using namespace std;

void sort (int a[], int n)
{
    int left = 0;
    int right = n - 1;
    int temp;
    while (left < right)
    {
        for (int i = left; i < right; i++)
        {
            if (a[i] > a[i+1])
            {
                temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
            }
        }
        right--;
        for (int i = right; i > left; i--)
        {
            if (a[i - 1] > a[i])
            {
                temp = a[i];
                a[i] = a[i - 1];
                a[i - 1] = temp;
            }
        }
        left++;
    }   
}