大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

单链表的折半查找,冒泡排序,选择排序-创新互联

//选择排序

创新互联10多年成都定制网页设计服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都定制网页设计及推广,对不锈钢雕塑等多个行业拥有多年的网站推广经验的网站建设公司。

void SelectSort(SeqList* pSeqList)

{

                int i = 0, j = 0;

                int iMaxPos = 0;

                int iMinPos = 0;

                DataType temp;

for (; i < pSeqList->Size/2; ++i)

  {

     iMaxPos = i;

     iMinPos = i;

    for(j = 1; j < pSeqList->Size - i; j++)

      {

      if (pSeqList->arry[iMaxPos] < pSeqList->arry[j])

           {

                 iMaxPos = j;

           }

      if (pSeqList->arry[iMinPos] > pSeqList->arry[j])

           {

               iMinPos = j;

            }

      }

    if (iMaxPos != i)

     {

          temp = pSeqList->arry[iMaxPos];

        pSeqList->arry[iMaxPos] = pSeqList->arry[pSeqList->Size - i - 1];

        pSeqList->arry[pSeqList->Size - i - 1] = temp;

      }

     if (iMinPos != i)

     {

         temp = pSeqList->arry[iMinPos];

          pSeqList->arry[iMinPos] = pSeqList->arry[i];

          pSeqList->arry[i] = temp;

      }

  }

}

//冒泡排序

void BorbbleSort(SeqList* pSeqList)

{

                int iCount = 0;

                int iBegin = 0;

                int iFlag = 0;

                if (NULL == pSeqList)

                {

                                return;

                }

    for (; iCount Size - 1; iCount++)

    {

        iFlag = 1;

        for (iBegin = 0; iBegin < pSeqList->Size - iCount - 1; ++iBegin)

        {

          if (pSeqList->arry[iBegin] > pSeqList->arry[iBegin+1])

           {

                DataType temp = pSeqList->arry[iBegin];

                pSeqList->arry[iBegin] = pSeqList->arry[iBegin+1];

                pSeqList->arry[iBegin+1] = temp;

                 iFlag = 0;

            }

          }

          if (iFlag)

          {

             return;

          }

     }

}

// 折半查找

int BinarySearch(SeqList* pSeqList, DataType data)

{

                int iLeft = 0;

                int iRight = pSeqList->Size;// [)

                //int iMid = (iLeft + iRight)/2;

                int iMid = 0;

                DataType temp;

                if (NULL == pSeqList)

                {

                                return;

                }

                // [0, 4]

                while(iLeft < iRight)

                {

                                iMid = iLeft + (iRight - iLeft)/2;

                                temp = pSeqList->arry[iMid];

                                if (temp < data)

                                {

                                                iLeft = iMid;

                                }

                                else if (temp > data)

                                {

                                                iRight = iMid - 1;

                                }

                                else

                                {

                                                return iMid;

                                }

                }

                return -1;

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:单链表的折半查找,冒泡排序,选择排序-创新互联
文章源于:http://dzwzjz.com/article/epooc.html
在线咨询
服务热线
服务热线:028-86922220
TOP