博客
关于我
C++基础之地址传递+数组冒泡排序实例
阅读量:359 次
发布时间:2019-03-04

本文共 589 字,大约阅读时间需要 1 分钟。

关键点:向函数传入数组首地址

#include 
using namespace std;/* 冒泡排序*/void bubbleSort(int *arr,int length){ for (int i = 0; i < length - 1; i++) { for (int j = 0; j < length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } }}/* 打印排序后的数组*/void printArray(int *arr, int length){ for (int i = 0; i < length; i++) { cout << arr[i] << endl; }}int main() { int arr[] = { 2,1,4,3,6,5,8,7,10,9 }; int length = sizeof(arr) / sizeof(arr[0]);//数组长度 bubbleSort(arr,length); printArray(arr, length); system("pause"); return 0;}

结果展示:

在这里插入图片描述

转载地址:http://qyxq.baihongyu.com/

你可能感兴趣的文章
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>