C Language "Sequential table" bubble sort, select the largest and smallest data at a time, binary lookup, initialization sequence table

Source: Internet
Author: User

#define  _CRT_SECURE_NO_WARNINGS 1#include<stdio.h> #include <assert.h> #include <stdlib.h > #include <string.h> #define  max_size 5typedef int datatype;typedef struct  seqlist{    size_t size;    datatype array[max_size];} seqlist;//Bubble sort//void swap (datatype *left, datatype *right)//{//     datatype tmp = *left;//    *left = *right;//     *right = tmp;//}////void bubblesort (SEQLIST*&NBSP;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;//  &nbSp;     }//    }//}////void test1 ()//{//     seqlist list;//    bubblesort (&list);//}////int main ()//{//     test1 ();//    system ("pause");//    return 0;// }//  the largest and smallest data is placed at each end of the sequence//void seclectsort (SEQLIST*&NBSP;PSEQ)//{//    int  I, j;//    int min;//    assert (PSEQ);//     for  (J&NBSP;=&NBSP;0;&NBSP;J&NBSP;&LT;&NBSP;PSEQ-&GT;SIZE&NBSP;-&NBSP;1;&NBSP;++J)//     {//        min = j;//         for  (i = j + 1; i < pseq->size; ++i )//        {//             if  (Pseq->array[min] > pseq->array[i])//             {//                 min = i;//            }//         }//        swap (& PSEQ-&GT;ARRAY[MIN],&NBSP;&AMP;PSEQ-&GT;ARRAY[J]);//    }//}////void seclectsort_op ( SEQLIST*&NBSP;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*&NBSP;PSEQ)//{//    assert (PSEQ);//    memset ( Pseq->size, 0, sizeof (DataType) *max_size);//    pseq->size = 0;/ /}


C Language "Sequential table" bubble sort, select the largest and smallest data at a time, binary lookup, initialization sequence table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.