Single-link table structure test program (linktest.cpp)

xiaoxiao2021-03-06  86

/// Single-link table structure test program /// # include #include #include "limited" link.h "#include" complex.h "

Void main () {// Node class test code Node a (10); Node b (20, & a); cout << b.nextnode () -> getData () << endl; node < INT> * pnode = new node (33, & b); cout << pnode-> nextnode () -> nextnode () -> getdata () << endl; delete pnode;

// linkedList class test code LinkedList L1; // Declaration Node Data is an int type Links LINKEDLIST L2; // Declaration Node Data is a chain of Complex Type Register Int i; for (i = 0; i <10; i ) {l1.insertfront (i); // header inserted into l2.insertrear (Complex (i, i * 1.5)); // Tablet insertion} l1.printlist (); // Output L1 (to the screen) L1.Reset (5); // Nonpoint to the bit sequence 5. Deletet (); // Delete the node of the current location L1.deleteat (); // Delete the current position Point l1.printlist (); // Output L1 L2.PrintList ("==>", 5); // Output L2, with a comma interval, 5 for each row (i = 0; i <100; i ) L2 . Deletetpos (5); // Delete the node of 5. L2.PrintList (); // Output L2 OFStream of ("Test.txt"); // New file stream L1.Printlist ("/ t", 2, of); / / output L1 to file, interval Tab (/ T), 2}

/ * Addition: The complex class complex is defined as follows: /// Complex.h /// # include Class Complex {// a biprivate: Double A, B; Public: Complex (double aa = 0, double BB = 0) {// Constructor A = AA; B = BB;} Complex (CONST COMPLEX & X) {// Constructor Overload (Copy Construction Function) A = Xa; B = Xb; } Double Real () {RETURN A;} // Real Double Image () {Return B;} // 虚 虚 Double R () {RETURN A;} // Take Double Double I () {Return B;} // 取 部 Void setRealPart (double aa) {a = aa;} // set realvial setImagePart (double bb) {b = bb;} // set imaginary part // ... Complex Operator ( Const Complex & X) Const {Return Complex (A XA, B XB);} Complex Operator (Double X) Const {Return Complex (A X, B);} Complex Operator- (Const Complex & X) Const {Return Complex (A - XA, B - XB);} // Other Operators' Overload (omitted) Friend Complex Operator (Double D, Const Complex & X); Friend Istream & Operator >> (ISTREAM & Stream, Complex & X); Friend Ostream & Operator << (Ostream & Stream, Const Comple) X & X); Friend Int Operator == (Const Complex & X, Const Complex & Y);

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

New Post(0)