Reverse array
数组颠倒算法
#include <iostream>
#include <iterator>
using namespace std; void reverse(int* A, int lo, int hi)
{
if (lo < hi)
{
swap(A[lo], A[hi]);
reverse(A, ++lo, --hi);
}
} void reverse(int* A,int n)
{
reverse(A, , n-);
}
int main()
{
int A[] = { , ,,,, };
reverse(A,); std::copy(std::begin(A), std::end(A), std::ostream_iterator<int>(std::cout, "\n"));
}
输出6,5,4,3,2,1
Reverse array的更多相关文章
- [Algorithm] Reverse array of Chars by word
For example we have: ["p", "r", "e", "f", "e", &qu ...
- reverse array java
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import ...
- CUDA学习,使用shared memory实现Reverse Array
- JavaScript Array 常用函数整理
按字母顺序整理 索引 Array.prototype.concat() Array.prototype.filter() Array.prototype.indexOf() Array.prototy ...
- Array 数组常用方法
(1)基本的数组方法 1.join() Array.join()方法将数组中所有元素都转化为字符串并连接在一起,返回最后生成的字符串.可以自己指定分隔的符号,如果不指定,默认使用逗号 var arr ...
- Lintcode: Recover Rotated Sorted Array
Given a rotated sorted array, recover it to sorted array in-place. Example [4, 5, 1, 2, 3] -> [1, ...
- AS3 - 数组Array的几个常用方法(附样例)
AS3 - 数组Array的几个常用方法(附样例) 2015-03-30 10:39发布:hangge浏览:241 Flex/Flash开发中,经常会使用到数组,下面总结了一些数组的常用方法. 1 ...
- 【leetcode】7. Reverse Integer
题目描述: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解题思 ...
- javascrip中array使用
一.测试数组长度是使用arr.length;(注:使用delete不会修改数组的length属性) 二.数组方法 1.join() Array.join()方法将数组所有元素都转化为字符串连接在一起, ...
随机推荐
- Linux 多个cpp文件的编译(Makefile)
打包so文件: CC = g++ CFLAGS=-Wall -O2 -fPIC TARGET = libbg.so SRCS := $(wildcard *.cpp) OBJS := $(patsub ...
- codeforces798C - Mike and gcd problem (数论+思维)
原题链接:http://codeforces.com/contest/798/problem/C 题意:有一个数列A,gcd(a1,a2,a3...,an)>1 时称这个数列是“漂亮”的.存在这 ...
- python中遍历列表字典元组
遍历列表,打印:我叫name,今年age岁,家住dizhi,电话phone lt = [ {'name':'小王', 'age':18, 'info':[('phone', '123'), ('diz ...
- 北风设计模式课程---解释器模式(Interpreter Pattern)
北风设计模式课程---解释器模式(Interpreter Pattern) 一.总结 一句话总结: 不仅要通过视频学,还要看别的博客里面的介绍,搜讲解,搜作用,搜实例 设计模式都是对生活的抽象,比如用 ...
- php7.0 新增运算符??
??是php7 新增符号 其作用近似于三目运算符 ?: 但存在着细微差别 比较示例代码如图: $b = $a?$a:2; 三目运算 <=> $e = $a??'ho ...
- linux从head.s到start_kernelstart_kernel之---内核解压到重定位分析
一: arm linux 内核生成过程 1. 依据arch/arm/kernel/vmlinux.lds 生成linux内核源码根目录下的vmlinux,这个vmlinux属于未压缩,带调试信息.符号 ...
- nRF51822 蓝牙低功耗和 2.4GHz 专利 SoC
DESCRIPTION nRF51822 是功能强大.高灵活性的多协议 SoC,非常适用于 Bluetooth® 低功耗和 2.4GHz 超低功耗无线应用. nRF51822 基于配备 256kB f ...
- JS 時間戳轉日期格式
1.日期轉換為時間戳,(如果日期格式為時間戳,將其轉為日期類型,否則輸出傳入的數據) // 如果時間格式為時間戳,將其轉為日期 function timestampToDate(timestamp) ...
- java 字符串的操作方法
方法 作用 范例 indexOf() 找到第一个字符出现的位置,()以下标来判断,返回的是字符所在的下标 int num = String.indexOf("字符") l ...
- How to show out three rows from the same databand On A4?
How to show out three rows from the same databand On A4? Quote Post by DoraHuang » Tue Mar 13, 2018 ...