School requires us to do data structures
Application of linear table - Warehouse management and diagram application - Engineering duration control problem. Since the establishment of these algorithm procedures are written in C or C languages, this time I decided to be a new try to use C # to edit these two An algorithm and configure the graphical interface to show the effect. Below is the two-way linked list I wrote.
Using
System; using
System.collections.Generic; Using
System.Text; Namespace
LJH.ListNode
{Public class objects {private int number; / ** // * Cargo number * / private string name; / ** // * Cargo name * / private int counter; / ** / * Number of goods * / / / Construction Function public objects (int Num, string name, int count) {number = Num; name = name; counter = count;} public int number {get {return number;} set {numler = value;}} public string name {Get {Return Name;} set {name = value;}} public int counter;} set {counter = value;}}} // Node class public class listNode {public listNode (Objects BUGS) { Goods = BUGS;} / ** //// /// Previous /// summary> public listNode previous; / ** //// /// Next /// < / summary> public listNode next; public listnode next;} set {next = value;}} / ** //// /// value /// summary> public objects goods; Public Objects Goods {Get {Return Goods;} set {goods = value;
}}} Public class clisms {public clism () {// Constructor // Initialization ListCountValue = 0; Head = NULL; TAIL = NULL;} / ** //// /// Name ///// summary> private string clistname = "Liu Jinghao"; public string clistname {get {return clistname;} set {clistname = value;}} / ** //// /// head pointer /// Summary> private listnode head; / ** //// /// Tail pointer /// summary> private listNode tail; / ** //// /// current pointer /// summary> private; public listNode current;} set {current = value;}} / ** //// /// Link table data /// summary> private int listcountvalue; / ** //// /// Tail Add data /// summary> public void append (Objects DataValue ) {ListNode NewNode = New ListNode (isnull ()) // If the head pointer is empty {head = newNode; tail = newNode;} else {tail.next = newNode; newode.previous = tail; tail = NewNode;} current = newNode;
// Link table data number plus one listCountValue = 1;} / ** //// /// Remove the current data /// summary> public void delete () {// If it is empty IF (! isnull ()) {// If the head IF (ISBOF ()) {head = current.next; current = head; listCountValue - = 1; return;} // If you delete the tail IF (ISEOF ()) { tail = Current.Previous; Tail.next = null; Current = tail; ListCountValue - = 1; return;} // if deleting the intermediate data Current.Previous.Next = Current.Next; Current = Current.Previous; ListCountValue - = 1 Return;}} / ** //// /// backward moving a data /// summary> Public void Movene xt () {if (! ity) current = current.next;} / ** //// // / forward moving a data /// summary> public void moveprevious () {i (! Isbof ()) current = current.previous;} / ** //// /// move to the first data /// summary> public void frist () {current = head;} / ** //// /// Move to the last data /// summary> public void movelast () {current = tail;} / ** /// /// judgment Is it empty list /// summary>
Public Bool Isnull () {if (listcountvalue == 0) return true;} / ** //// /// judgment is to reach the end /// summary> Public Bool ISEOF () {If (current == tail) Return true; return false;} / ** //// /// judgment is to reach the head /// summary> public bool isbof () {= {ix (CURRENT == Head) Return true;} public objects getcurrentValue () {return current.goods;} / ** //// /// getting the data number of the list /// summary> Public INT ListCount {Get {Return ListCountValue;}} / ** //// /// Empty Link list /// summary> public void clear () {movefrist (); while (! isnull ()) { // If it is not empty, from the tail Delete delete ();}} / ** //// /// Insert data before the current position is inserted /// summary> public void insert (Objects DataValue) {listNode NewNode = New ListNode (DataValue); If (isnull ()) {// is a blanket, add append (data;} if (isbof ()) {// is inserted into newnode.next = head for the head; Head.Previous = newNode; Head = NEWNODE; current = head; listcountvalue = 1; Return;
} // interposition NewNode.Next = Current; NewNode.Previous = Current.Previous; Current.Previous.Next = NewNode; Current.Previous = NewNode; Current = NewNode; ListCountValue = 1;} / ** //// /// Decorption Insert /// /// summary> public void insertascending (Objects InsertValue) {// Parameters: InsertValue Inserted data // Empty list if (isnull ()) {// Add append (InsertValue) ); Return;} // moved to head movefrist (); if ((InsertValue.Number /// Insert /// summary> / ** // * Cargo storage * / public void insertunascending (Objects INSERTVALUE) {// Parameters: InsertValue Inserted data // is an empty list if (isnull ()) {// Add Append (InsertValue); Return;} // moves to the head MoveFrist ();
IF (InsertValue.Number> getCurrentValue () {// meets the condition, insert, exit insert (InsertValue);} while (TRUE) {if (InsertValue.Number> getCurrentValue (). Number) {// When you meet the conditions, insert it, exit insert (InsertValue); Break;} if (ISEOF ()) {// Tail Add append (InsertValue); Break;} // Move to the next pointer MOVENEXT ();}} // Name Query Cargo 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;} // The ID for the 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 ==