# Include <iostream> using namespace STD; struct node {int D; struct node * Next;}; // define node * build1 () // create a single-chain table {node * P; // point to the new node * head; // the header pointer head = NULL; P = head; int X; cin> X; while (X! =-1) {P = new node; P-> d = x; P-> next = head; head = P; CIN> X;} return head ;} node * build2 () // tail inserts a single-chain table {node * head; // head pointer node * P, * s; // P points to the current node, s points to the End Node head = NULL; P = head; S = head; int X; CIN> X; while (X! =-1) {P = new node; P-> d = x; If (! Head) Head = P; else S-> next = P; S = P; CIN> X;} If (s) S-> next = NULL; return head ;} int main () {node * P; P = build2 (); While (P! = NULL) {cout <(p-> D); P = p-> next;} return 0 ;}
This article is from the "7883538" blog, please be sure to keep this source http://7893538.blog.51cto.com/7883538/1435486