不常用,可以看一下实现原理

namespace UnilateralismChainTable
{
// 结点类
public class ListNode
{
public ListNode(int NewValue)
{
Value = NewValue;
} //前一个
public ListNode Previous; // 后一个
public ListNode Next; // 值
public int Value;
}
// 定义结点之后,开始类线性表的操作编程了.在LIST 类中,采用了,Head ,Tail, Current,三个指针,使用Append ,
//MoveFrist,MovePrevious,MoveNext,MoveLast ,Delete,InsertAscending,InsertUnAscending ,Clear 实现移动,添加,
//删除,升序插入,降序插入,清空链表操作,GetCurrentValue() 方法取得当前的值。
public class Clist
{
public Clist()
{
//构造函数
//初始化
ListCountValue = ;
Head = null;
Tail = null;
} // 头指针
private ListNode Head; // 尾指针
private ListNode Tail; // 当前指针
private ListNode Current; //链表数据的个数
private int ListCountValue; //尾部添加数据
public void Append(int DataValue)
{
ListNode NewNode = new ListNode(DataValue); if (IsNull()) //如果头指针为空
{
Head = NewNode;
Tail = NewNode;
}
else
{
Tail.Next = NewNode;
NewNode.Previous = Tail;
Tail = NewNode;
}
Current = NewNode;
//链表数据个数加一
ListCountValue += ;
}
//删除当前的数据
public void Delete()
{
//若为空链表
if (!IsNull())
{
//若删除头
if (IsBof())
{
Head = Current.Next;
Current = Head;
ListCountValue -= ;
return;
} //若删除尾
if (IsEof())
{
Tail = Current.Previous;
Current = Tail;
ListCountValue -= ;
return;
} //若删除中间数据
Current.Previous.Next = Current.Next;
Current = Current.Previous;
ListCountValue -= ;
return;
}
} // 向后移动一个数据
public void MoveNext()
{
if (!IsEof()) Current = Current.Next;
} // 向前移动一个数据
public void MovePrevious()
{
if (!IsBof()) Current = Current.Previous;
} // 移动到第一个数据
public void MoveFrist()
{
Current = Head;
} // 移动到最后一个数据
public void MoveLast()
{
Current = Tail;
} // 判断是否为空链表
public bool IsNull()
{
if (ListCountValue == )
return true; return false;
} // 判断是否为到达尾
public bool IsEof()
{
if (Current == Tail)
return true;
return false;
} // 判断是否为到达头部
public bool IsBof()
{
if (Current == Head)
return true;
return false; } public int GetCurrentValue()
{
return Current.Value;
} // 取得链表的数据个数
public int ListCount
{
get
{
return ListCountValue;
}
} // 清空链表
public void Clear()
{
MoveFrist();
while (!IsNull())
{
//若不为空链表,从尾部删除
Delete();
}
} // 在当前位置前插入数据
public void Insert(int DataValue)
{
ListNode NewNode = new ListNode(DataValue);
if (IsNull())
{
//为空表,则添加
Append(DataValue);
return;
} if (IsBof())
{
//为头部插入
NewNode.Next = Head;
Head.Previous = NewNode;
Head = NewNode;
Current = Head;
ListCountValue += ;
return;
}
//中间插入
NewNode.Next = Current;
NewNode.Previous = Current.Previous;
Current.Previous.Next = NewNode;
Current.Previous = NewNode;
Current = NewNode;
ListCountValue += ;
} // 进行升序插入
public void InsertAscending(int InsertValue)
{
//参数:InsertValue 插入的数据
//为空链表
if (IsNull())
{
//添加
Append(InsertValue);
return;
} //移动到头
MoveFrist();
if ((InsertValue < GetCurrentValue()))
{
//满足条件,则插入,退出
Insert(InsertValue);
return;
}
while (true)
{
if (InsertValue < GetCurrentValue())
{
//满族条件,则插入,退出
Insert(InsertValue);
break;
}
if (IsEof())
{
//尾部添加
Append(InsertValue);
break;
}
//移动到下一个指针
MoveNext();
}
}
//进行降序插入
public void InsertUnAscending(int InsertValue)
{
//参数:InsertValue 插入的数据
//为空链表
if (IsNull())
{
//添加
Append(InsertValue);
return;
}
//移动到头
MoveFrist();
if (InsertValue > GetCurrentValue())
{
//满足条件,则插入,退出
Insert(InsertValue);
return;
}
while (true)
{
if (InsertValue > GetCurrentValue())
{
//满族条件,则插入,退出
Insert(InsertValue);
break;
}
if (IsEof())
{
//尾部添加
Append(InsertValue);
break;
}
//移动到下一个指针
MoveNext();
}
}
} }

模拟货物的入库和出库:

namespace BothChainTable
{
public class Objects
{
private int number; /**//* 货物编号 */
private string name; /**//* 货物名称 */
private int counter; /**//* 货物数量 */ //构造函数
public Objects(int num, string Name, int count)
{
number = num;
name = Name;
counter = count;
}
public int Number
{
get
{
return number;
}
set
{
number = value;
}
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Counter
{
get
{
return counter;
}
set
{
counter = value;
}
}
} // 结点类
public class ListNode
{
public ListNode(Objects bugs)
{
goods = bugs;
}
/**/
/// <summary>
/// 前一个
/// </summary>
public ListNode Previous; /**/
/// <summary>
/// 后一个
/// </summary>
public ListNode Next;
public ListNode next
{
get
{
return Next;
}
set
{
Next = value;
}
}
/**/
/// <summary>
/// 值
/// </summary>
public Objects goods;
public Objects Goods
{
get
{
return goods;
}
set
{
goods = value;
}
}
} public class Clists
{
public Clists()
{
//构造函数
//初始化
ListCountValue = ;
Head = null;
Tail = null;
}
/**/
/// <summary>
/// 表名
/// </summary>
private string clistname = "";
public string ClistName
{
get
{
return clistname;
}
set
{
clistname = value;
}
}
/**/
/// <summary>
/// 头指针
/// </summary>
private ListNode Head; /**/
/// <summary>
/// 尾指针
/// </summary>
private ListNode Tail; /**/
/// <summary>
/// 当前指针
/// </summary>
private ListNode Current;
public ListNode current
{
get
{
return Current;
}
set
{
Current = value;
}
} /**/
/// <summary>
/// 链表数据的个数
/// </summary>
private int ListCountValue; /**/
/// <summary>
/// 尾部添加数据
/// </summary> public void Append(Objects DataValue)
{
ListNode NewNode = new ListNode(DataValue); if (IsNull()) //如果头指针为空
{
Head = NewNode; Tail = NewNode;
}
else
{
Tail.Next = NewNode; NewNode.Previous = Tail; Tail = NewNode;
} Current = NewNode; //链表数据个数加一 ListCountValue += ; } /**/
/// <summary>
/// 删除当前的数据
/// </summary>
public void Delete()
{
//若为空链表 if (!IsNull())
{
//若删除头 if (IsBof())
{
Head = Current.Next;
Current = Head;
ListCountValue -= ;
return;
} //若删除尾 if (IsEof())
{
Tail = Current.Previous; Tail.next = null; Current = Tail; ListCountValue -= ; return;
} //若删除中间数据 Current.Previous.Next = Current.Next; Current = Current.Previous; ListCountValue -= ; return;
}
}
/**/
/// <summary>
/// 向后移动一个数据
/// </summary>
public void MoveNext()
{
if (!IsEof()) Current = Current.Next;
}
/**/
/// <summary>
/// 向前移动一个数据
/// </summary>
public void MovePrevious()
{
if (!IsBof()) Current = Current.Previous;
}
/**/
/// <summary>
/// 移动到第一个数据
/// </summary>
public void MoveFrist()
{
Current = Head;
} /**/
/// <summary>
/// 移动到最后一个数据
/// </summary>
public void MoveLast()
{
Current = Tail;
}
/**/
/// <summary>
/// 判断是否为空链表
/// </summary>
public bool IsNull()
{
if (ListCountValue == )
return true;
else
return false;
} /**/
/// <summary>
/// 判断是否为到达尾部
/// </summary>
public bool IsEof()
{
if (Current == Tail)
return true;
else
return false;
}
/**/
/// <summary>
/// 判断是否为到达头部
/// </summary>
public bool IsBof()
{
if (Current == Head)
return true;
else
return false; } public Objects GetCurrentValue()
{
return Current.goods;
} /**/
/// <summary>
/// 取得链表的数据个数
/// </summary> public int ListCount
{
get
{
return ListCountValue;
}
} /**/
/// <summary>
/// 清空链表
/// </summary> public void Clear()
{
MoveFrist();
while (!IsNull())
{
//若不为空链表,从尾部删除
Delete();
}
} /**/
/// <summary>
/// 在当前位置前插入数据
/// </summary> public void Insert(Objects DataValue)
{
ListNode NewNode = new ListNode(DataValue);
if (IsNull())
{
//为空表,则添加
Append(DataValue);
return;
} if (IsBof())
{
//为头部插入
NewNode.Next = Head;
Head.Previous = NewNode;
Head = NewNode;
Current = Head;
ListCountValue += ;
return;
}
//中间插入
NewNode.Next = Current;
NewNode.Previous = Current.Previous;
Current.Previous.Next = NewNode;
Current.Previous = NewNode;
Current = NewNode;
ListCountValue += ;
} /**/
/// <summary>
/// 进行升序插入
/// </summary> public void InsertAscending(Objects InsertValue)
{
//参数:InsertValue 插入的数据
//为空链表
if (IsNull())
{
//添加
Append(InsertValue);
return;
}
//移动到头
MoveFrist();
if ((InsertValue.Number < GetCurrentValue().Number))
{
//满足条件,则插入,退出
Insert(InsertValue);
return;
}
while (true)
{
if (InsertValue.Number < GetCurrentValue().Number)
{
//满族条件,则插入,退出
Insert(InsertValue);
break;
} if (IsEof())
{
//尾部添加
Append(InsertValue);
break;
}
//移动到下一个指针
MoveNext();
}
}
/**/
/// <summary>
/// 进行降序插入
/// </summary> /**/
/*货物入库*/
public void InsertUnAscending(Objects InsertValue)
{
//参数:InsertValue 插入的数据
//为空链表
if (IsNull())
{
//添加
Append(InsertValue);
return;
}
//移动到头
MoveFrist();
if (InsertValue.Number > GetCurrentValue().Number)
{
//满足条件,则插入,退出
Insert(InsertValue);
return;
}
while (true)
{
if (InsertValue.Number > GetCurrentValue().Number)
{
//满足条件,则插入,退出
Insert(InsertValue);
break;
} if (IsEof())
{
//尾部添加
Append(InsertValue);
break;
}
//移动到下一个指针
MoveNext();
}
}
//根据名字查询货物
public Objects FindObjects(string name)
{
ListNode lnode = Head;
if (IsNull())
{
return null;
}
else if (IsEof())
{
return null;
}
else
while (lnode.goods.Name != name)
{
if (lnode.Next == null)
{
Current = lnode;
return null;
}
lnode = lnode.Next;
}
Current = lnode;
return lnode.goods;
}
//根据编号查询货物
public Objects FindObjects(int number)
{
ListNode lnode = Head;
if (IsNull())
{
return null;
}
else if (IsEof())
{
return null;
}
else
while (lnode.goods.Number != number)
{
if (lnode.Next == null)
{
Current = lnode;
return null;
}
lnode = lnode.Next;
}
Current = lnode;
return lnode.goods;
}
/**/
/*货物出库*/
//根据名字删除货物
public Objects DeleteObjects(string name)
{
Objects bugs;
bugs = FindObjects(name);
Delete();
return bugs;
}
//根据编号删除货物
public Objects DeleteObjects(int number)
{
Objects bugs;
bugs = FindObjects(number);
Delete();
return bugs;
}
}
}

ListNode线性表的更多相关文章

  1. C语言 线性表 链式表结构 实现

    一个单链式实现的线性表 mList (GCC编译). /** * @brief 线性表的链式实现 (单链表) * @author wid * @date 2013-10-21 * * @note 若代 ...

  2. 线性表(gcc实现)

    线性结构: ①存在一个唯一的被称为“第一个”的数据元素: ②存在一个唯一的被称为“最后一个”的数据元素: ③除第一个元素外,每个元素均有唯一一个直接前驱: ④除最后一个元素外,每个元素均有唯一一个直接 ...

  3. 数据结构与算法(C#)入门 --- 线性表

    线性表: 线性表是最简单,最基本,最常用的数据结构.线性表中的数据元素之间存在一对一的关系.即:除了第一个元素,其他元素前面有且只有一个元素:除了最后一个元素,其他元素后面有且只有一个元素.生活中的例 ...

  4. 第2章 线性表《C#数据结构和算法》

    ( )除第一个位置的数据 元素外,其它数据元素位置的前面都只有一个数据元素:( )除最后一个位置的 数据元素外,其它数据元素位置的后面都只有一个元素.也就是说,数据元素是 一个接一个的排列.因此,可以 ...

  5. c++实验3 链式存储线性表

    1.线性表链式存储结构及基本操作算法实现 (1)单链表存储结构类的定义: #include <iostream> using namespace std; template <cla ...

  6. 线性表 - C语言完整实现

    #include <stdio.h> #define false 0 #define true 1 #define MAXSIZE 20 typedef int bool; typedef ...

  7. 线性表的链式存储——C语言实现

    SeqList.h #ifndef _WBM_LIST_H_ #define _WBM_LIST_H_ typedef void List; typedef void ListNode; //创建并且 ...

  8. 线性表List

    数组array是基本的数据结构,但它的功能有限,线性表list可以认为是扩展了功能的数组.可以自动调整大小.添加和删除元素不需要其他元素移位. 根据指针数量和指向的不同,线性表分为单向链表.双向链表和 ...

  9. [从今天开始修炼数据结构]线性表及其实现以及实现有Itertor的ArrayList和LinkedList

    一.线性表 1,什么是线性表 线性表就是零个或多个数据元素的有限序列.线性表中的每个元素只能有零个或一个前驱元素,零个或一个后继元素.在较复杂的线性表中,一个数据元素可以由若干个数据项组成.比如牵手排 ...

随机推荐

  1. JS基础——数组总结

    JS中数组被觉得是一种对象,慢慢的,怎么忽然感觉,JS中仅仅要能够独立出来的概念怎么都能够当成对象来解释呢?有点儿怀疑.继续学吧.先来总结一下JS中数组是怎样详细使用的. 一.创建 数组的创建在JS中 ...

  2. hdu 4115 石头剪子布(2-sat问题)

    /* 意甲冠军:石头剪子布,目前已知n周围bob会有什么,对alice限制.供u,v,w:设w=0说明a,b回合必须出的一样 否则,必须不一样.alice假设输一回合就输了,否则就赢了 解: 2-sa ...

  3. react学习笔记1--基础知识

    什么是react A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES[React是一个用于构建用户界面的JavaScript库.] React之所以快, ...

  4. /proc/mtd 各参数的含义 -- linux内核

    经/proc虚拟文件系统读取MTD分区表:cat /proc/mtd mtd .name = raspi, .size = 0x00400000 (4M) .erasesize = 0x0001000 ...

  5. 使用C#实现顺序队列

    队列(Queue)是插入操作限定在表的尾部而其它操作限定在表的头部进行的线性表.把进行插入操作的表尾称为队尾(Rear),把进行其它操作的头部称为队头(Front).当对列中没有数据元素时称为空对列( ...

  6. C#如何设置session过期时间

    1.操作系统  步骤:开始——〉管理工具——〉Internet信息服务(IIS)管理器——〉网站——〉默认网站——〉  右键“属性”——〉主目录——〉配置——〉选项——〉启用会话状态——〉会话超时(在 ...

  7. kobject_create_and_add

    本文来源于源linux 3.14.3版本号/lib/kobject.c文件 /**  * kobject_create_and_add - 动态地创建kobject结构和寄存器sysfs  *  * ...

  8. 文《左右c++与java中国的垃圾问题的分析与解决》一bug分析

    文<左右c++与java中国的垃圾问题的分析与解决>一bug分析 DionysosLai(906391500@qq.com) 2014/10/21 在前几篇一博客<关于c++与jav ...

  9. 深度-first遍历图--邻接表实现

    在这里,邻接表的实现与深度优先遍历图,使用递归. #include<iostream> using namespace std; #define VERTEXNUM 5//结点数 stru ...

  10. Python - 安全替换字符串模板(safe_substitute) 详细解释

    安全替换字符串模板(safe_substitute) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/27057339 字 ...