⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userinfolist.java

📁 这是我课程设计的时候做的聊天程序
💻 JAVA
字号:
/*
 * Created on 2005-12-18
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package chatRoom;
//import javax.swing.*;
//import java.net.*;
//import java.io.*;
/**
 * @author hongyuan
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
class UserInfoList {
	Node root;  //用户信息链表的根
	Node pointer;  //用于操作链表的游标
	int count;//链表中的元素个数
	public UserInfoList()
	{
		root=new Node();//创建链表根节点
		root.next=null;
		pointer=null;
		count=0;//初始元素为0
	}
	//实现用户信息节点的添加功能(在链表尾部加)
	public void add(Node n)
	{
		pointer=root;//将游标指向根节点
		while(pointer.next!=null)
		{
			pointer=pointer.next;//将游标往后移
		}
		pointer.next=n;//加入节点
		n.next=null;
		count++;//节点数加1
	}
	//实现用户信息节点的删除功能
	public void del(Node n)
	{
		pointer=root;//将游标指向根节点
		while(pointer.next!=null)//判断是否到达链表尾部
		{
			if(pointer.next==n)//判断下一个节点是不是要删除的节点
			{
				pointer.next=n.next;
				count--;//节点数减1
				break;
			}			
		}	
	}
	//返回链表元素个数
	public int getCount()
	{
		return count;
	}
	//定义find(),为方便查找,进行重载,入口参数分别为String类型的用户昵称和int型的相对于根节点的索引
	public Node find(String username)
	{
		if(count==0) 
			return null;
		pointer=root;//将游标指向根节点
		while(pointer.next!=null)//判断是否到达链表尾部
		{
			pointer=pointer.next;//游标后移
			if(pointer.username.equalsIgnoreCase(username))//判断是否找到昵称为username的节点
			{
				return pointer;//返回找到的元素的节点
			}			
		}	
		return null;		
	}
	public Node find(int index)
	{
		if(count==0) 
			return null;
		if(index<0)
			return null;
		pointer=root;//将游标指向根节点
		int i=0;
		while(i<index+1)//判断是否到达链表尾部
		{
			if(pointer.next!=null)
				pointer=pointer.next;//游标后移
			else
				return null;
			i++;
		}	
		return null;	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -