Data Structure Course Design ----- Implement two-way linked list with C #

xiaoxiao2021-03-17  217

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 /// public listNode previous; / ** //// /// Next /// < / summary> public listNode next; public listnode next;} set {next = value;}} / ** //// /// value /// 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 ///// private string clistname = "Liu Jinghao"; public string clistname {get {return clistname;} set {clistname = value;}} / ** //// /// head pointer /// private listnode head; / ** //// /// Tail pointer /// private listNode tail; / ** //// /// current pointer /// private; public listNode current;} set {current = value;}} / ** //// /// Link table data /// private int listcountvalue; / ** //// /// Tail Add data /// 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 /// 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 /// Public void Movene xt () {if (! ity) current = current.next;} / ** //// // / forward moving a data /// public void moveprevious () {i (! Isbof ()) current = current.previous;} / ** //// /// move to the first data /// public void frist () {current = head;} / ** //// /// Move to the last data /// public void movelast () {current = tail;} / ** /// /// judgment Is it empty list ///

Public Bool Isnull () {if (listcountvalue == 0) return true;} / ** ////

/// judgment is to reach the end /// Public Bool ISEOF () {If (current == tail) Return true; return false;} / ** //// /// judgment is to reach the head /// public bool isbof () {= {ix (CURRENT == Head) Return true;} public objects getcurrentValue () {return current.goods;} / ** //// /// getting the data number of the list /// Public INT ListCount {Get {Return ListCountValue;}} / ** //// /// Empty Link list /// public void clear () {movefrist (); while (! isnull ()) { // If it is not empty, from the tail Delete delete ();}} / ** //// /// Insert data before the current position is inserted /// 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 /// 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 /// / ** // * 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 ==

转载请注明原文地址:https://www.9cbs.com/read-129664.html

New Post(0)