博客
关于我
数据结构的学习历程02
阅读量:342 次
发布时间:2019-03-04

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

数据结构的学习历程02

杨辉三角

在这里插入图片描述

public class Demo01 {       public static void main(String[] args) {           Scanner sc = new Scanner(System.in);        System.out.println("请输入杨辉三角的行数:");        int n =sc.nextInt();        List
> ret = YH(n); for (;n>0;n--){ System.out.println(ret.get(5-n)); } } public static List
> YH(int n) { if (n==0) return null; List
> ret =new ArrayList<>(); for (int i = 0;i
cur =new ArrayList<>(); if (i == 0){ cur.add(1); ret.add(cur); continue; } cur.add(1); for (int j = 1 ;j < i;j++){ cur.add(ret.get(i-1).get(j-1)+ret.get(i-1).get(j)); } cur.add(1); ret.add(cur); } return ret; }}

先进后出的数据结构,类型为Stack。

如题

一个栈的入栈序列为abc123,则这个栈的不可能出栈序列为:A  abc123   每进一个出一个B  acb321   进1出1 进2出2 进3出3C  321bac   因为3先出,所以进了6个数据,而c最后出,则不可能,故选CD  321cba   进6出6

进栈出栈

进栈:push()

出栈:pop()
获取栈顶元素:peek()

栈的实现

中缀表达式(前、后缀表达式)(选)

而在栈中输入后缀表达式时,遇到变量/常量先入栈,遇到运算符号则出栈顶两个变量/常量。第一个数字为这个运算符的右操作数,第二个数字就为运算符的左操作数。

队列

先进先出的数据结构,类型为Queue

进队出队

进队:offer()

出队:poll()
获取队头元素:peek()

队列的实现

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

你可能感兴趣的文章
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>