package Binary;
public class SinglyList<T> extends Object{
public Node<T> head;
public SinglyList()
{
this.head=new Node<T>();
}
public SinglyList(T[] values)
{
this();
Node<T>rear=this.head;
for(int i=0;i<values.length;i++)
{
rear.next=new Node<T>(values[i],null);
rear=rear.next;
}
}
public SinglyList(SinglyList<T>list)
{ this();
Node<T> rear=this.head;
for (Node<T> p=list.head.next; p!=null; p=p.next)
{ rear.next = new Node<T>(p.date, null);
rear = rear.next;
}
}
public boolean isEmpty()
{
return this.head.next==null;
}
public T get(int i)
{
Node<T>p=this.head.next;
for(int j=0;p!=null&&j<i;j++)
p=p.next;
return(i>=0&&p!=null)?p.date:null;
}
public void set(int i,T x)
{
Node<T>p=head.next;
if(i<this.size()&&x!=null) {
for(int j=0;j<i;j++)
p=p.next;
p.date=x;}
}
public int size()
{
int i=0;
Node<T>p=head;
while(p!=null) {
p=p.next;
i++;}
return i;
}
public String toString()
{
String str=this.getClass().getName()+"(";
for(Node<T>p=this.head.next;p!=null;p=p.next)
{
str+=p.date.toString();
if(p.next!=null)
str+=",";
}
return str+")";
}
public Node<T>insert(int i,T x)
{
if(x==null)
throw new NullPointerException("x==null");
Node<T>front=this.head;
for(int j=0;front.next!=null&&j<i;j++)
front=front.next;
front.next=new Node<T>(x,front.next);
return front.next;
}
public Node<T> insert(T x)
{
return insert(Integer.MAX_VALUE,x);
}
public T remove(int i)
{
Node<T> front=this.head;
for(int j=0;front.next!=null&&j<i;j++)
front=front.next;
if(i>=0&&front.next!=null)
{
T old=front.next.date;
front.next=front.next.next;
return old;
}
return null;
}
public void clear()
{
this.head.next=null;
}
public SinglyList(SinglyList<T> list, boolean asc)
{
this();
Node<T> rear=this.head;
Node<T> p=null;
Node<T> q=rear.next;
for(Node<T>r=list.head.next;r!=null;r=r.next)
{
int i=(int)p.date;
int j=(int)r.date;
if(asc)
if(i>=j)
q.date=r.date;
else
p=new Node<T>(r.date,p.next);
else if(i<=j)
q.date=r.date;
else p=new Node<T>(r.date,p.next);
p=q;
q=new Node<T>(null,head);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
b.zip_java_otherzrq
共2个文件
java:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 142 浏览量
2022-09-20
11:52:02
上传
评论
收藏 2KB ZIP 举报
温馨提示
二叉树以广义表的形式构造,依次由递归、堆栈和parent链遍历。
资源推荐
资源详情
资源评论
收起资源包目录
b.zip (2个子文件)
b
SinglyList.java 2KB
Schedule.java 2KB
共 2 条
- 1
资源评论
寒泊
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功