在下决定之前,向已经在工作岗位上的前辈请教过考研还是工作的问题。我知道只有这些人才最有资格讨论这个问题,当然出来研究领域的大牛。我也知道会有很多不同的答案,甚至有的非常的绝对或者说极端,但我更相信一句话:事在人为!
我决定考研了,理由我这里就不多说了。此时此刻的该受是自己的学习能力还不够,研究问题的脑袋还没有成熟,我向变得更加冷静,更加沉着,力求达到自己的考研目的。就像有的前辈说的:除了基本外,争取有利于自己事业的一技之长。
但决定归决定,现在还没有到冲刺的时候,所以现在仍然是提高自己基础的时候,特别是这个时候自己已经有了一定基础,有更有利的条件自己去研究解决一些问题。
为了增强自己的学习能里,于是在认真学习这几门专业课之时候,自学一下java数据结构(学院开的是用c描述的,多少有差别),争取早点学完。
今天做完了第一个程序:链表的基本功能:
package comeon.feiqiang;
/**
* this class is for a Node Oprator
* include tow menber variables data and link
* with the methods provided,you can create a new IntNode with two parameters,
* create a new Node before the current Node,create a copy with head,create a copy with head and tail
* get
*
*/
public class IntNode {
public int data;
public IntNode link;
public IntNode(int initialData, IntNode initialLink) {
data = initialData;
link = initialLink;
}
public void addNodeBefore(int element) {
link = new IntNode(element, link);
}
/**
* @param head
* @return the head of the list
*/
public static IntNode listCopy(IntNode head) {
IntNode answer = null;
if (head == null) {
return null;
}
IntNode cursor = head;
answer = new IntNode(head.data, null);
IntNode tail = answer;
while (cursor.link != null){
cursor = cursor.link;
tail.link=new IntNode(cursor.data, tail.link);
tail = tail.link;
}
return answer;
}
/**
* @param IntNode
* source
* @return an array with the head and the tail of a copy of a source list
*/
public static IntNode[] copyWithDail(IntNode source) {
IntNode copyHead = null;
IntNode copyTail = null;
IntNode[] answer = new IntNode[2];
if (source == null) {
return answer;
}
copyHead = new IntNode(source.data, null);
copyTail = copyHead;
source = source.link;
while (source != null) {
copyTail.link = new IntNode(source.data, copyTail.link);
source = source.link;
copyTail = copyTail.link;
}
answer[0] = copyHead;
answer[1] = copyTail;
return answer;
}
/**
* @param head
* @return the length of the list
*/
public static int listLength(IntNode head) {
int answer = 0;
IntNode cursor = head;
while (cursor != null) {
answer++;
cursor = cursor.link;
}
return answer;
}
/**
*
* @param start
* @param end
* @return a copy of the current list from the start Node to the end Node
*/
public static IntNode[] listPart(IntNode start, IntNode end) {
IntNode copyHead = null;
IntNode copyTail = null;
IntNode answer[] = new IntNode[2];
if (start == null) {
throw new IllegalArgumentException("start is null");
}
if (end == null) {
throw new IllegalArgumentException("end is null");
}
copyHead = new IntNode(start.data, null);
copyTail = copyHead;
while (start != end) {
start = start.link;
if (start == null) {
throw new IllegalArgumentException(
"end node was not found on this list");
}
copyTail.link = new IntNode(start.data, copyTail.link);
copyTail = copyTail.link;
}
answer[0] = copyHead;
answer[1] = copyTail;
return answer;
}
/**
* @param head
* @param position
* @return the IntNode on the position
*/
public static IntNode listPosition(IntNode head, int position) {
if (position <= 0) {
throw new IllegalArgumentException("position is not positive");
}
IntNode cursor = head;
for (int i = 1; i < position && cursor != null; i++) {
cursor = cursor.link;
}
return cursor;
}
/**
* @param IntNode
* head
* @param IntNode
* target
* @return the IntNode at the data of target
*/
public static IntNode listSearch(IntNode head, int target) {
IntNode cursor = head;
while (cursor != null) {
if (cursor.data == target) {
return cursor;
}
cursor = cursor.link;
}
return null;
}
public static void print(IntNode head) {
IntNode cursor = head;
while (cursor != null) {
System.out.println(cursor.data);
cursor = cursor.link;
}
}
}
分享到:
相关推荐
一个用链表管理节点指针的类。 可以有两种方式提取,先入先出和遍历的方式。 是我自己工作中使用的。 应该是比较方便,现提供出来方便大家。
* 基于位置接口实现的双向链表节点类 */ package dsa; public class DLNode implements Position { private Object element;//数据对象 private DLNode prev;//指向前驱节点 private DLNode next;//指向后继...
数据结构 链表节点的删除 通过三种方法对链表节点进行删除。
这是一个单向链表,它具有插入与删除节点的功能。Entry类实现了链表的各节点。
用链表类的节点存放一个类对象,读取excel一行多字段数据信息,创建excel和读取excel,货真价实;
节点类双向头结点循环链表
封装了链表的操作,功能有链表的创建,节点的添加(附加),插入(前插、后插和插入到链表头部),删除,得到节点数据,得到节点位置,得到节点总数,释放链表。 使用了类模版,使得可以让节点中的数据为任意类型,...
1. 请创建一个数据类型为T的链表类模板List,实现以下成员函数: 1) 默认构造函数List(),将该链表初始化为一个空链表(10分) 2) 拷贝构造函数List(const List<T>& list),根据一个给定的链表构造当前链表(10...
尤其是,当用链表描述不同的数据结构时,节点结构体的定义都是不同的,这就需要为每一种链表都写一套诸如插入、删除节点之类的操作代码。 本程序就是为了解决这个问题,将双向链表的基本操作写成了一套通用程序,...
数据结构经典算法演示,这里是链表-插入节点的代码演示
数据结构 初始化链表,插入删除节点,遍历链表,链表长度,找出中间节点
操作一个链表,链表中的节点有两个指针,一个指向下一个节点, 一个指向下下一个节点,如果下一个节点或者下下一个节点为空,则为null。 操作为插入,删除,修改。 博客:...
输入年龄,若和链表内节点相同,删除该节点
耿国华版数据结构二叉链表叶子节点输出的完整程序,上机试过了,希望能帮到有需要的人。
请设计一个链表类,实现链表的初始化、插入、删除和打印操作。 节点的定义如下: typedef int elementType; typedef struct node { elementType data; node* next; } LList, *PList; 链表类的定义及要求...
定义、实现并测试一个双向链表结点类DNode。...编写主程序:输入不少于3组x、y整数,分别利用左侧和右侧插入结点函数组织数据为双向链表,测试输出链表中每个结点的左侧和右侧相邻节点内容,测试对左右侧结点的删除。
自己编写的链表类,声明和实现 功能: 创建链表,插入节点,删除节点,输出链表,求出链表长度
链表类 c++ 实现的 链表类 c++ 实现的 链表类 c++ 实现的
数据结构c语言版链表删除重复节点,包含数据类型、结构的定义和函数的实现