In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to sort and find C++, the article is very detailed, has a certain reference value, interested friends must read it!
1. Sort the array by bubbling (ascending order)
# include # include
Void sort (int a [], int n) {int I, j, t; for (I = 0; I
< n-1 ; i++) { for (j = 0; j < n-1; j++) { if (a[j] >A [juni1]) {t = a [j]; a [j] = a [juni1]; a [juni1] = t;}
Int main () {int a [5], I; for (I = 0; I
< 5; i++) { printf("input a[%d]=", i); scanf("%d", &a[i]); } sort(a, 5); for (i = 0; i < 5; i++) { printf("%4d", a[i]); } system("pause"); return 0;} 2、用插入法排序将输入到数组中的元素进行排序 #include #include void fun(int a[], int n){ int k, j, t; for (j = 1; j < n; j++) { t = a[j]; k = j - 1; while (k >= 0 & t > a [k]) {a [k + 1] = a [k]; kmuri;} a [k + 1] = t;}}
Int main () {int a [5], I; for (I = 0; I
< 5; i++) { printf("input a[%d]=", i); scanf("%d", &a[i]); } fun(a, 5); for (i = 0; i < 5; i++) { printf("%4d", a[i]); } system("pause"); return 0;} 3、用选择法将输入的10个数进行排序 #include #include int main(){ int i, j, min, tem, a[10]; for (i = 0; i < 10; i++) { printf("input a[%d]=", i); scanf("%d", &a[i]); } for (i = 0; i < 10; i++) { printf("%d", a[i]); } for (i = 0; i < 10 - 1; i++) { min = i; for (j = i + 1; j < 10; j++) { if (a[min] >A [j]) {min = j;} tem = a [I]; a [I] = a [min]; a [min] = tem;} printf ("\ n"); for (I = 0; I < 10; iTunes +) {printf ("% d", a [I]);} system ("pause"); return 0;}
4. Using the half-and-half search method, you will check whether the entered number is in the ascending array of 10 elements, and if so, which number it is.
# include # include
Int main () {int a [10] = {12 int a [10] = {12 Peregra [10] = {12 Peregrine 32 [10] = {12 Peregrine 76pyrorn 85pyrorn]; int num, bott, top, mid; printf ("input a number:"); scanf ("% d", & num); bott = 0; top = 9; while (bott top) {printf ("no\ n");} system ("pause"); return 0;} above are all the contents of this article entitled "how to sort and find C++". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.