////MAIN.C//pointers and Arrays////Created by Chu Cowei on 15/7/25.//Copyright (c) 2015 Chu Cowei. All rights reserved.//#include <stdio.h>#define N 4//bubble method with pointer implementation//Inputint*enternumber ();//SortvoidSORTNUMBERASC (int*PTR);//OutputvoidPrintnumber (int*PTR);int*enternumber () {//Input Static intAry[n];printf("Please enter a set of numbers:"); for(intI=0; i<n; i++) {scanf("%d", &ary[i]); }int*p=ary;returnP;}voidSORTNUMBERASC (int*PTR) {//Sort intTEMPN;intI,j;int*ptr_old=ptr;//Record the beginning address of the pointer for(i=0; i<n-1; i++) {ptr=ptr_old;//After loop PTR points to the address after the array, so you need to re-point the pointer to the initial address for(j=0; j<n-1-I.; J + +) {if(*ptr<* (ptr+1)) {tempn=*ptr; *ptr=* (ptr+1); * (ptr+1) =tempn; } ptr++; } }}voidPrintnumber (int*PTR) {//Output printf("The number after sorting is:"); for(intI=0; i<n; i++) {printf("%d", *ptr); ptr++; }printf("\ n");}intMainintargcConst Char* argv[]) {//bubble method with pointer implementation: //Input int*ptr=enternumber ();//SortSORTNUMBERASC (PTR);//OutputPrintnumber (PTR);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C language-bubble sort with pointers 2