链表(java实现)

Link.java

public class Link{
private Node first;
public Link(){
this.first = null;
}
//判断是否为空
public boolean isEmpty(){
if(this.first == null)
return true;
return false;
}
//插入头结点
public void insertHeadNode(int data){
Node tmp = new Node(data);
if(this.first == null)
first = tmp;
else
{
tmp.setNext(first.getNext());
first.setNext(tmp);
}
return ;
}
//在第index下插入data节点
public void insertNode(int data, int index){
Node p = this.first;
int cnt = 0;
while(cnt != index){
p = p.getNext();
cnt++;
}
Node newNode = new Node(data);
newNode.setNext(p.getNext());
p.setNext(newNode);
return ; }
//delete the head node
public Node deleteHeadNode(){
Node tmp = first;
this.first = tmp.getNext();
return tmp;
}
//find the data in the link
public Node findNode(int data){
Node p = this.first;
while(p != null){
if(p.getData() == data)
return p;
if(p == null)
break;
p = p.getNext();
}
return null;
}
//display the link
public void displayLink(){
Node p = first;
while(p != null){
System.out.println(p.getData());
p = p.getNext();
}
return ;
}
}

Node.java

public class Node{
private int data;
private Node next;
//construction
public Node(){
this.data = 0;
this.next = null;
}
public Node(int data){
this.data = data;
this.next = null;
}
//get
public Node getNext(){
return this.next;
}
public int getData(){
return data;
} //set
public void setNext(Node next){
this.next = next;
}
public void setData(int data){
this.data = data;
}
//show
public void nodeDisplay(){
System.out.println("{"+data+"}");
}
}

TestOfNode.java

public class TestOfNode{
public static void main(String[] args){
//test of Node
Node tmp1 = new Node(100);
tmp1.nodeDisplay(); Link tmp2 = new Link();
//test of insertHeadNode & displayLink
tmp2.insertHeadNode(00);
tmp2.displayLink();
//test of isEmpty
System.out.println(tmp2.isEmpty());
System.out.println("+++++\n\n");
//test of insertNode
tmp2.insertNode(11,0);
tmp2.insertNode(22,1);
tmp2.insertNode(33,2);
tmp2.insertNode(44,3);
tmp2.insertNode(55,4);
tmp2.insertNode(66,5);
tmp2.displayLink();
//test of delete the head Node
System.out.println("++++");
tmp2.deleteHeadNode();
tmp2.displayLink();
//test of find the data
if(tmp2.findNode(3310)!=null){
System.out.println("truely find the data:" + 3310);
}else{
System.out.println("fasle");
} System.out.println("++++++"); //test of InsertHeadNode
tmp2.insertHeadNode(1111);
tmp2.insertHeadNode(2222);
tmp2.insertHeadNode(3333);
tmp2.displayLink();
}
}

排序 - 国家金牌银牌铜牌分别排序

TestOfNode.java

public class TestOfNode{
public static void main(String[] args){
//test of Node
Node tmp1 = new Node(100);
tmp1.nodeDisplay(); Link tmp2 = new Link();
//test of insertHeadNode & displayLink
tmp2.insertHeadNode(00);
tmp2.displayLink();
//test of isEmpty
System.out.println(tmp2.isEmpty());
System.out.println("+++++\n\n");
//test of insertNode
tmp2.insertNode(11,0);
tmp2.insertNode(22,1);
tmp2.insertNode(33,2);
tmp2.insertNode(44,3);
tmp2.insertNode(55,4);
tmp2.insertNode(66,5);
tmp2.displayLink();
//test of delete the head Node
System.out.println("++++");
tmp2.deleteHeadNode();
tmp2.displayLink();
//test of find the data
if(tmp2.findNode(3310)!=null){
System.out.println("truely find the data:" + 3310);
}else{
System.out.println("fasle");
} System.out.println("++++++"); //test of InsertHeadNode
tmp2.insertHeadNode(1111);
tmp2.insertHeadNode(2222);
tmp2.insertHeadNode(3333);
tmp2.displayLink();
}
}

Test.java

import java.util.Arrays;

public class Test{
public static void main(String[] args){
Country American = new Country(46,37,38);
Country English = new Country(27,23,17);
Country China = new Country(26,18,26);
Country Russia = new Country(19,18,19);
Country Germany = new Country(17,10,15); Country[] countrys = new Country[5];
countrys[0] = American;
countrys[1] = English;
countrys[2] = China;
countrys[3] = Russia;
countrys[4] = Germany;
Arrays.sort(countrys);
for(Country cty:countrys)
System.out.println(cty.gold + " " + cty.silver + " " + cty.copper + " " + cty.sum); }
}

Coffee 类 - 面向对象编程

Coffee.java

package coffee;

//增加的方法
abstract class AddImplement{
private String name;
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public abstract void add();
}
class AddSugarImplement extends AddImplement{
public void add(){
System.out.println("you have added the Sugar^_^");
}
}
class AddMilkImplement extends AddImplement{
public void add(){
System.out.println("you have added the Milk ^_^");
}
}
//抽象类的实现
public abstract class Coffee{
private AddImplement addimpl;
//然后在调用add进行输出
public void add(){
addimpl.add();
};
//应该先调用这个设置函数
public void setAddImpl(AddImplement addimpl){
this.addimpl = addimpl;
};
} class InstantCoffee extends Coffee{
public void setAddImpl(AddImplement addimpl){
System.out.println("This is an InstantCoffee^_^");
super.setAddImpl(addimpl);
}
} class LatteCoffee extends Coffee{
public void
setAddImpl(AddImplement addimpl){
System.out.println("This is a LatteCoffee^_^");
super.setAddImpl(addimpl);
}
} class MochaCoffee extends Coffee{
public void setAddImpl(AddImplement addimpl){
System.out.println("This is a MochaCoffee^_^");
super.setAddImpl(addimpl);
}
}

MainTest.java

package coffee;

import java.util.Scanner;
public class MainTest { public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String choice = new String();
String addsth = new String();
while(true){
System.out.println("What kind of coffe would you want ?");
choice = in.nextLine();
System.out.println("What would you like to add ?Sugar or Milk?");
addsth = in.nextLine();
if(choice.equals("InstantCoffee")){
Coffee c1 = new InstantCoffee();
if(addsth.equals("Sugar")){
AddImplement a1 = new AddSugarImplement();
c1.setAddImpl(a1);
c1.add();
}else if(addsth.equals("Milk")){
AddImplement a2 = new AddMilkImplement();
c1.setAddImpl(a2);
c1.add();
}else{
System.out.println("Sorry,we don't have this kind of things *_*");
}
}else if(choice.equals("LatteCoffee")){
Coffee c1 = new LatteCoffee();
if(addsth.equals("Sugar")){
AddImplement a1 = new AddSugarImplement();
c1.setAddImpl(a1);
c1.add();
}else if(addsth.equals("Milk")){
AddImplement a2 = new AddMilkImplement();
c1.setAddImpl(a2);
c1.add();
}else{
System.out.println("Sorry,we don't have this kind of things *_*");
}
}else if(choice.equals("MochaCoffee")){
Coffee c1 = new MochaCoffee();
if(addsth.equals("Sugar")){
AddImplement a1 = new AddSugarImplement();
c1.setAddImpl(a1);
c1.add();
}else if(addsth.equals("Milk")){
AddImplement a2 = new AddMilkImplement();
c1.setAddImpl(a2);
c1.add();
}else{
System.out.println("Sorry,we don't have this kind of things *_*");
}
}else{
System.out.println("We don't have this kind of Coffee*_*");
}
} } }

模拟一个文件复制过程

Test.java

package test;

//系统成分类
abstract class attribute{
int cnt;
// public abstract void operation1();
public abstract void output();
public abstract void copy();
public abstract void traverseDirectory();
}
//目录类
class Folder extends attribute{
private attribute [] parts = new attribute[100];
private String name;
public int cnt = 0;
private int index = 0;
//构造函数部分
Folder(){}
Folder(String name){
this.name = name;
}
//复制操作
// public void operation1(){
// System.out.println("复制文件:" + name);
// }
public void output(){
System.out.println("+" + name);
}
public void add(Folder name){
parts[index] = name;
index++;
name.cnt = this.cnt + 1;
}
public void add(File name){
parts[index] = name;
index++;
name.cnt = this.cnt + 1;
}
public boolean remove(attribute a){
for(int i = 0 ; i < index ;i++){
if(parts[i].equals(a)){
parts[i] = null;
return true;
}
}
return false;
}
//有几个操作
public int getchild(){
return index;
}
//遍历操作
public void traverseDirectory(){
this.output();
for(int i = 0 ; i < index; i++){
for(int k = 0 ; k <= this.cnt; k++){
System.out.print(" ");
}
this.parts[i].traverseDirectory();
}
}
public void copy(){
System.out.println("复制文件:" + name);
for(int j = 0 ; j < this.index ;j++){
this.parts[j].copy();
}
}
}
//文件类
class File extends attribute{
public String name;
public int cnt = 0;
File(String name){
this.name = new String(name);
}
public void output(){
System.out.println("-" + name);
}
public void copy(){
System.out.println("复制文件:" + name);
}
// public void operation1(){
// System.out.println("复制文件:" + name);
// }
public void traverseDirectory(){
this.output();
}
} public class Test{
public static StringBuffer st = new StringBuffer();
public static void main(String[] args){
Folder document = new Folder("我的资料");
File book = new File("Java编程思想.pdf");
Folder music = new Folder("我的音乐");
File music1 = new File("你是我的眼.mp3");
File music2 = new File("Without You.mp3");
Folder picture = new Folder("我的照片");
File pic1 = new File("我在美国白宫的照片");
File pic2 = new File("我在新加坡的照片");
File pic3 = new File("我在南极的照片");
File pic4 = new File("我在南非的照片");
File pic5 = new File("我与习大大的合影"); document.add(book);
document.add(music);
music.add(music1);
music.add(music2);
picture.add(pic1);
picture.add(pic2);
picture.add(pic3);
picture.add(pic4);
picture.add(pic5); document.copy();
System.out.println("-------------------------------");
document.traverseDirectory();
picture.traverseDirectory();
}
}

Java实习二的更多相关文章

  1. 最近找java实习面试被问到的东西总结(Java方向)

    时间,就是这么很悄悄的溜走了将近两个年华,不知不觉的,研二了,作为一个一般学校的研究生,不知道该说自己是不学无术,还是说有过努力,反正,这两年里,有过坚持,有过堕落,这不,突然间,有种开窍的急迫感,寻 ...

  2. 广州三本找Java实习经历

    前言 只有光头才能变强 这阵子跑去面试Java实习生啦~~~我来简单介绍一下背景吧. 广州三本大三在读,在广州找实习.大学开始接触编程,一个非常平庸的人. 在学习编程时,跟我类似的人应该会有一个疑问: ...

  3. 两个月的Java实习结束,继续努力

    前言 只有光头才能变强 2018年8月30日,今天我辞职了.在6月25号入职,到现在也有两个月时间了. 感受: 第一天是期待的:第一次将项目拉到本地上看的时候,代码很多,有非常多的模块,模块下又有da ...

  4. 从零基础到拿到网易Java实习offer,谈谈我的学习经验

    微信公众号[程序员江湖] 作者黄小斜,斜杠青年,某985硕士,阿里 Java 研发工程师,于 2018 年秋招拿到 BAT 头条.网易.滴滴等 8 个大厂 offer,目前致力于分享这几年的学习经验. ...

  5. 从零基础到拿到网易Java实习offer,我做对了哪些事

    作为一个非科班小白,我在读研期间基本是自学Java,从一开始几乎零基础,只有一点点数据结构和Java方面的基础,到最终获得网易游戏的Java实习offer,我大概用了半年左右的时间.本文将会讲到我在这 ...

  6. Java EE : 二、图解 Cookie(小甜饼)

    目录 Java EE : 一.图解Http协议 Java EE : 二.图解 Cookie(小甜饼) Java EE : 三.图解Session(会话) 概述 一.概述 二.详细介绍Cookie 传输 ...

  7. 利用JAVA生成二维码

    本文章整理于慕课网的学习视频<JAVA生成二维码>,如果想看视频内容请移步慕课网. 维基百科上对于二维码的解释. 二维条码是指在一维条码的基础上扩展出另一维具有可读性的条码,使用黑白矩形图 ...

  8. java实现二维码

    说起二维码,微信好像最先启用,随后各类二维码就开始流行起来了.那什么是二维码呢. 1.什么是二维码?百度一下即可 http://baike.baidu.com/view/132241.htm?fr=a ...

  9. Java 设计模式(二)-六大原则

    Java 设计模式(二)-六大原则 单一职责原则(Single Responsibility Principle) 定义: 不要存在多余一个原因导致类变更,既一个类只负责一项职责. 问题由来: 当类A ...

随机推荐

  1. CentOS安装python-2.7+安装pip-10.0.0

    注:以下所有操作均在CentOS 6.8 x86_64位系统下完成. 首先查看当前系统预装的python版本: # whereis python python2: /usr/bin/python2 / ...

  2. Divisibility by Eight---cf550C(被8整除 暴力)

    题目链接:http://codeforces.com/problemset/problem/550/C 题意是给你一个不操过100位的数,问删除m位之后,问剩下的数不改变顺序能被8整除的数存在不存在: ...

  3. Preparing Olympiad---cf550B(DFS或者状态压缩模板)

    比赛链接:http://codeforces.com/problemset/problem/550/B 给你n个数,选出来只是2个然后求他们的和在L和R的区间内,并且选出来的数中最大值和最小值的差不得 ...

  4. js的class属性获取、增加、移除

    2018年4月10日,北京城的第三份工作已经开始,坚信自己在这里能学到很多,加油! 贴代码,昨天回顾了一点js知识: <script> $(function(){ //赋予一个点击事件 $ ...

  5. qemu进程页表和EPT的同步问题

    背景分析: 在之前分析EPT violation的时候,没有太注意qemu进程页表和EPT的关系,从虚拟机运行过程分析,虚拟机访存使用自身页表和EPT完成地址转换,没有用到qemu进程页表,所以也就想 ...

  6. VC2005 warning C4819 消除方法

    一. Warning C4819:The file contains a character that can ot be represented in the current code page(9 ...

  7. C的指针疑惑:C和指针13(高级指针话题)上

    int *f(); f为一个函数,返回值类型是一个指向整形的指针. int (*f)(); 两对括号,第二对括号是函数调用操作符,但第一对括号只起到聚组的作用. f为一个函数指针,它所指向的函数返回一 ...

  8. SVM数学原理推导&鸢尾花实例

    //看了多少遍SVM的数学原理讲解,就是不懂,对偶形式推导也是不懂,看来我真的是不太适合学数学啊,这是面试前最后一次认真的看,并且使用了sklearn包中的SVM来进行实现了一个鸢尾花分类的实例,进行 ...

  9. Get started on your own KD 8 custom colorway

    The 2009 Summer time Nike Basketball revealed the Cheap KD 8 and revealed three MVP-inspired colors ...

  10. POJ - 1966 Cable TV Network (最大流求点连通度)

    题意:求一个无向图的点连通度.点联通度是指,一张图最少删掉几个点使该图不连通:若本身是非连通图,则点连通度为0. 分析:无向图的点连通度可以转化为最大流解决.方法是:1.任意选择一个点作为源点:2.枚 ...