C ++ lin table operation

xiaoxiao2021-03-06  115

#include

Struct student {Int Num; int score; struct.

Int n;

Struct student * createlink () {strunt * p1 = null; struct student * p2 = null; int NUM = 1; int score = 11; n = 0; p1 = new struct student (); p2 = P1; if (p1 == null) {cout << "/ ncann't create it, try it again in a moment! / n"; return null;} else {head = null; p1-> num = NUM ​​ ; P1 -> score = score ;} while (p1-> num <10) {n = 1; if (n == 1) {head = p1; p2-> next = null;} else {p2-> next = P1 P2 = p1; p1 = new structure (); p1-> num = Num ; p1-> score = score ;} p2-> next = null; delete (p1); p1 = null; return head;}

Void Print {struct student * p; p = head; if (Head! = null) {DO {COUT <

<< '/ t'

Num << '/ t' <

Score << '/ t'

NEXT <

P = P-> next;

}

While (p! = null);

}

}

Struct Student * deletelink (strunt news * head, int num) {structure * p1; struct student * p2; if (head == null) {cout << "/ nlist is null! / n"; return head;} ​​P1 = Head; while (p1-> num! = NUM ​​&& P1-> Next! = null) {p2 = p1; p1 = p1-> next;}

IF (NUM == P1-> Num) {if (p1 == HEAD) {head = p1-> next;} else {p2-> next = p1-> next;} delete p1; p1 = null; n - = 1;} else {cout << "/ nnot been all! / N";

Return head;

Struct Student * InsertLink (Struct Studient * Head, Int Num, Struct Student * Node) {struct student * p1; if (head == null) {head = node; node-> next = null; n = 1; return head }

P1 = head; while (p1-> num! = NUM ​​&& P1-> Next! = null) {p1 = p1-> next;} if (num == p1-> num) {node-> next = p1-> Next; p1-> next = node; n = 1;} else {cout << "/ nnot been found! / n";

Return head;

Struct Student * Reverselink (struct student * head) {struct student * p; struct student * p1; struct student * p2;

P1 = NULL; P2 = head; while (p2! = null) {p = p2-> next; p2-> next = p1; p1 = p2; p2 = p;} head = p1; return head;}

Void main () {struct student * head; struct student * stu; int theumber;

HEAD = CREATELINK (); Print (HEAD);

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

New Post(0)