DS:using Stack to arrange the array to get max number.
来源:互联网 发布:mac 重新安装jenkins 编辑:程序博客网 时间:2024/05/22 14:18
what follows is code to demonstrate:
#include "stdafx.h"#include <malloc.h>#include <stdio.h>#include <string.h>#include<time.h>#include<stdlib.h> #define N 5 //control number of arrayint clic =1;int max(int a[],int sub){int t;if(sub==1)return a[0];else t= max(a,sub-1);{printf("\nt%d:%d\n",clic,t);clic=clic+1;}if(t>a[sub-1])return t;else return a[sub-1];}int main(int argc, char* argv[]){int a[N];srand(time(NULL)); for(int i = 0; i < N; i ++) { a[i]=rand()/100; printf("a[%d]:%d\t",i,a[i]); } printf("\nmax:%d\n",max(a,N));printf("\nclick:%d\n",clic);return 0;}
the word,"last in first out ",is most imagic in the stack,i think the way that make up the array is a good example .
the process by order I think like this:
5th step: return a[0]
4th step: t=max(a,1)--->return t or a[1]
3rd step: t=max(a,2)--->return t or a[2]
2nd step: t=max(a,3)--->return t or a[3]
1st step: t=max(a,4)--->return t or a[4]
Simplely,the hypothesis i think is that the member of array,a[0],compare the rest one by order to return t max number.
阅读全文
0 0
- DS:using Stack to arrange the array to get max number.
- How to get the default value in the paramter block description of 3ds max
- Reorder array to construct the minimum number
- Array to Stack
- How to show 3D object (.3DS or .MAX) in MATLAB using JMonkey
- [Dynamic Programming]Recursion/Non-recursion to find the max number
- a interface to stack that implement use the fixed array.
- zoj1074 To the Max
- 1074 To the Max
- 1050 To the Max
- POJ1050 To the Max
- POJ1050 To the Max
- POJ to The Max
- 1081 To The Max
- To the Max
- To the max(hdu1081)
- POJ To the Max
- 1050--To the Max
- Linux下最简单完整的samba服务器搭建
- 依据parentId动态构建一颗树
- Java经典算法40例(三十六)
- 指针数组和数组指针梳理
- Spring Cloud学习笔记之12-Factor
- DS:using Stack to arrange the array to get max number.
- mybatis(9)--整合ehcache
- Android的死机、重启问题分析方法
- VIM设置,自动换行
- 将文件做成镜像文件
- define,require的基本用法
- 关于使用DecimalFormat的进行四舍五入
- Java经典算法40例(三十七)
- web网页测试注意事项