📄 user.java
字号:
import javax.swing.*;
import java.net.*;
import java.io.*;
public class User{
Dan root;//用户信息链表的根
Dan pointer;//操作链表的游标
int count;//元数个数
public User()
{
root=new Dan();//创建根结点
root.next=null;
pointer=null;
count=0;//初始化
}
public void add(Dan n)//用户信息节点的添加功能
{
pointer=root;//将游标指向根节点
while(pointer.next!=null)//判断游标是否在链表的尾部
{
pointer=pointer.next;//将游标后移
}
pointer.next=n;//加入结点
n.next=null;
count++;//计数器加1
}
public void del(Dan n)//用户信息节点的删除功能
{
pointer=root;//将游标指向根节点
while(pointer.next!=null)//判断游标是否在链表尾部
{
if(pointer.next==n)//判断当前节点是否是要删除的
{
pointer.next=n.next;//删除节点
count--;//计数器减1
break;
}
pointer=pointer.next;//将游标指向下一节点
}
}
public int getCount()//返回链表中的元素个数
{
return count;
}
public Dan find(String username)//用户信息节点查找功能(以用户名为参)
{
if(count==0)return null;//如果链表元素个数为0,则直接返回
pointer=root;//将游标移到根节点
while(pointer.next!=null)//判断是否到达链表尾部
{
pointer=pointer.next;//游标后移
if(pointer.username.equalsIgnoreCase(username))
{
return pointer;//返回找到的无素的节点
}
}
return null;
}
public Dan find(int index)//用户信息节点查找功能(以链表排序为参)
{
if(count==0)//如果链表元素个数为0,则直接返回
{
return null;
}
if(index<0)//如果指定的索引小于0,则直接返回
{
return null;
}
pointer=root;//将游标移至根节点
int i=0;
while(i<index+1)//判断是否到达链表尾部
{
if(pointer.next!=null)
{
pointer=pointer.next;//将游标后移
}
else
{
return null;
}
i++;
}
return pointer;//返回找到的元素节点
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -