Create and display C ++ book numbers and price linked lists

Source: Internet
Author: User
# Include <iostream> using namespace STD; Class book // create a book class {public: int num; double price; book * Next ;}; book * head = NULL; // assign the header node A blank book * creat () // create the linked list function {book * P1, * P2; // P1 points to the new object, p2 points to the next node p1 = new book; head = p1; P2 = p1; // first point the three pointers to the same node cout <"Enter the book number, end with 0. "<Endl; CIN> P1-> num; // If the input num is not 0, enter priceif (P1-> num! = 0) {cout <"Enter the price of the book:" <Endl; CIN> P1-> price;} else // if it is equal to 0, the object will be deleted, leave the last object empty and return the header pointer {Delete P1; P2 = NULL; P2-> next = NULL; return head;} while (P1-> num! = 0) // enter num and price continuously, and until num is 0; {P2 = p1; P1 = new book; cout <"Enter the book number, end with 0 "<Endl; CIN> P1-> num; If (P1-> num! = 0) {cout <"Enter the price of the book:" <Endl; CIN> P1-> price;} P2-> next = p1;} Delete P1; // if it is equal to 0, the object will be deleted, the last object will be null, And the header pointer P2-> next = NULL; return head;} void showbook (Book * head) will be returned) {cout <Endl; cout <"Book information:" <Endl; while (head) {cout <"book no: "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.