[Stack first-in-first-out] [Queue first-out]
A linear table is the most basic, simple, and commonly used data structure. The relationship between data elements in a linear table is one-to-one, that is, except the first and last data elements, other data elements are connected at the beginning and end. The logical structure of a linear table is simple for implementation and operation. Therefore, the linear table data structure is widely used in practical applications.
Stack first-in-first-out
Public static void QuueMain () {// create a Queue named Queue myQ = new Queue (); myQ. enqueue ("The"); // enter myQ. enqueue ("quick"); myQ. enqueue ("brown"); myQ. enqueue ("fox"); myQ. enqueue (null); // Add null myQ. enqueue ("fox"); // Add duplicate elements // print the number of queues and value Console. writeLine ("myQ"); Console. writeLine ("\ tCount: {0}", myQ. count); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); // print the first element in the Queue and remove the Console. writeLine ("(Dequeue) \ t {0}", myQ. dequeue (); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); // print the first element in the Queue and remove the Console. writeLine ("(Dequeue) \ t {0}", myQ. dequeue (); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); // print the first element in the Queue Console. writeLine ("(Peek) \ t {0}", myQ. peek (); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); Console. readLine ();} public static void PrintValues (IEnumerable myCollection) {foreach (Object obj in myCollection) Console. write ("{0}", obj); Console. writeLine ();}
Queue (Queue) first-in-first-out
Public static void StackMain () {Stack stack Stack = new stack (); Stack. push ("one"); stack. push ("two"); stack. push ("three"); stack. push ("four"); stack. push ("five"); // print the number of queues and the value Console. writeLine ("Stack"); Console. writeLine ("\ tCount: {0}", stack. count); // print all values in the queue Console. write ("Stack values:"); PrintValues (stack); // print the first element at the top of the queue and remove the Console. writeLine ("(Pop) \ t {0}", stack. pop (); // print all values in the queue Console. write ("Stack values:"); PrintValues (stack); // print the Console, the first element at the top of the queue. writeLine ("(Peek) \ t {0}", stack. peek (); // print all values in the queue Console. write ("stack values:"); PrintValues (stack); Console. readLine ();} public static void PrintValues (IEnumerable myCollection) {foreach (Object obj in myCollection) Console. write ("{0}", obj); Console. writeLine ();}