Ruizhi Ma's Blog

Keep Calm and Carry On

单链表

单链表的实现(创建节点,追加节点,获取下一个节点)

代码实现 Node类 package demo2; public class Node { //节点内容 int data; //下一个节点 Node next; public Node(int data){ this.data = data; } //为节点追加节点 public Node append(Node node){ //当前节点 No...

队列的实现

入队,出队,判空

队列底层实现 package demo2; public class MyQueue { //初始化一个数组 int[] elements; public MyQueue(){ elements = new int[0]; } //入队 public void add(int element){ //创建一个新的数组 int[] newArr = new int...

栈的实现

压入,弹出,查看栈的元素,以及栈是否为空

栈的底层实现 package stack; public class MyStack { //用数组写栈的底层 int[] elements; public MyStack(){ elements = new int[0]; } //往数组中压入元素 public void push(int element){ //创建一个新的数组 int[] newArr...

Problem 189

Rotate Array

问题描述 Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the righ...

JAVA入门第二季结课大作业

答答租车系统

要求:开发一个租车系统。 功能: 展示所有可租车型 选择车型,租车量 展示租车清单,包括:总金额,总载货量,车型,总载人数,以及车型 分析 数据模型分析:将车的信息抽象为代码表示。车可分为载人的(Saloon Cars),载货的(Trucks),既载人也载货的(Pickups)。所以车的属性应该有车的名字,载客量,载货量。 业务模型分析:要明确应用程序要执行哪些...

查找数组元素

线性查找和二分查找

线性查找 package array; public class ArrayLinearSearch { public static void main(String[] args) { //targer array int[] arr = new int[] {12,23,5,4,656,76}; //target element int target = 5;...

Problem 277

Find the Celebrity

问题描述 Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her ...

对数组元素进行操作

增加,删除,取出,插入和替换

数据结构之数组操作 数据结构同步开始入门,今天做了一点简单的操作: 往数组末尾添加元素 删除指定下标的元素 取出指定下标的元素 插入某个元素到数组的指定下标位置 替换指定位置的元素 package array; public class TestMyArray { public static void main(String[] args) { MyArr...

Problem 80

Remove Duplicates from Sorted ArrayII

题目描述 Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array, you must do thi...

JAVA内部类,成员内部类,静态内部类,方法内部类

概念区分和用法简介

内部类 什么是内部类? 内部类,顾名思义就是定义在另一个类之内的类。 内部类有什么好处?(官方说法。编程实践太少了,没有形成自己的认知,以后有体会,回来再根据自己认知改一改!) 内部类提供了更好的封装,可以把内部类隐藏在外部类之内,不允许同一个包中的其他类访问该类 内部类的方法可以直接访问外部类的所有数据,包括私有的数据 内部类所实现...