2020.4.30
第九天了,明天就放假了,连网课都不用上了~
今天写的是数组的逆序输出
Java 代码
import java.util.Scanner;
/*
* 反转排序
*/
class ReverseSort {
public void Sort(int a[]) {
int length = a.length, temp;
for (int i = 0; i < length / 2; i++) {
temp = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = temp;
}
Show(a);
}
public void Show(int a[]) {
for (int n : a) {
System.out.print(n + " ");
}
}
}
public class NumeberReverse {
public static void main(String[] args) {
int a[] = new int[10];
Scanner input = new Scanner(System.in);
for (int i = 0; i < a.length; i++) {
a[i] = input.nextInt();
}
ReverseSort sort = new ReverseSort();
sort.Sort(a);
}
}
C 代码
看到有人用栈写这道题,我那古老的记忆里也想起来了~!
#include<stdio.h>
#define N 10
int main()
{
int stack[N], top = -1;
while (top != N - 1)
{
scanf("%d", &stack[++top]);
}
while (top != -1)
{
printf("%d ", stack[top--]);
}
return 0;
}
假期前的最后一天~~
如有错误恳请大佬指正,感觉不尽~~
算法题目来源:https://www.dotcpp.com/