2排序

來源:互聯網
上載者:User

  就是數組中資料要麼是這個, 要麼是那個.不錯的思想,貌似簡單,其實不學不可能會.

  我覺得寫遊戲的時候會派上用場.例如,兩個幫派群P,之後分組.你說呢?呵呵.

 /*7-31-11-26-22.22.c -- 第七章第三十一題*/<br />#include <stdio.h></p><p>#define SIZE 21<br />#define FALSE 0<br />#define TRUE 2</p><p>int main (void) ;<br />void print_array (const int * const array, const int size) ;<br />void swap (int * const vala, int * const valb) ;</p><p>int main (void)<br />{<br />const int MAYBE = 1 ;<br />int array[SIZE] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE} ;<br />int size = SIZE, i = 0, j = size - 1, index, dummy ;</p><p>print_array (array, size) ;<br />index = (size - 1) / 2 ;<br />dummy = MAYBE ;<br />swap (array + index, &dummy) ;<br />while (1)<br />{<br />while (FALSE == array[i])<br />i++ ;<br />while (TRUE == array[j])<br />j-- ;<br />if (i < j)<br />swap (array + i, array + j) ;<br />else<br />break ;<br />}<br />swap (array + i, &dummy) ;<br />print_array (array, size) ;</p><p>return 0 ;<br />}</p><p>void print_array (const int * const array, const int size)<br />{<br />int i ; </p><p>for (i = 0; i < size; i++)<br />printf ("%s/n", FALSE == array[i] ? "FALSE" : "TRUE") ;<br />putchar ('/n') ;<br />}</p><p>void swap (int * const vala, int * const valb)<br />{<br />int temp ;</p><p>temp = *vala ;<br />*vala = *valb ;<br />*valb = temp ;<br />}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.