📄 slistnode.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace Example
{
class SListnode
{
internal int data;
internal SListnode next;
public SListnode()
{
next = null;
}
public SListnode(int data)
{
this.data = data;
next = null;
}
public SListnode(int data, SListnode next)
{
this.next = next;
this.data = data;
}
public SListnode Nextnode()
{
return next;
}
public int Getdata()
{
return data;
}
}
class SList
{
public SListnode head;
public SListnode current;
public SList()
{
head = null;
current = null;
}
public void MakeEmpty()
{
head.next = null;
current = head;
}
public int Length()
{
if (current != null)
{
SListnode a = head;
int i = 0;
while (a.next != null)
{
a = a.next;
i++;
}
return i;
}
else
{
return -1;
}
}
public void SetCurrent(SListnode cp)
{
current = cp;
}
public SListnode GetCurrent()
{
return current;
}
public SListnode Getnext()
{
return current.next;
}
public SListnode Gethead()
{
return head;
}
public SListnode getnode(int i)
{
if (i < 0)
return null;
if (i == 0)
return head;
SListnode p = head;
for (int j = 1; p != null && j <= i; j++)
{
p = p.next;
}
return current;
}
//在单链表的当前结点的位置前插入一个值为item的结点
public void insert(int value,bool before)
{
if (current == head)
before = false;
SListnode newnode;
if (before)
{
SListnode p = head;
while (p.next != current)
p = p.next;
newnode = new SListnode(value, p.next);
p.next = newnode;
}
else
{
newnode = new SListnode(value, current.next );
current.next = newnode;
}
}
public void insert(int value, int i)
{
if (i < 1)
i = 1;
if(i>Length()+1)
i=Length()+1;
SListnode p=getnode(i-1);
SListnode newnode = new SListnode(value, p.next);
p.next = newnode;
}
public void delete()
{
if (current == head)
return;
SListnode p = head;
while (p.next != current)
p = p.next;
p.next = current.next;
if (p.next != null)
current = p.next;
else
current = p;
}
public void modifydata(int value)
{ current.data = value; }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -