C language-bubble sort with pointers 2

Source: Internet
Author: User

////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

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.