Dynamic Linked List experience and dynamic experience

Source: Internet
Author: User

Dynamic Linked List experience and dynamic experience

# Include <iostream> using namespace std; struct Node {int date; // the data of the Node struct Node * next; // point to the next Node}; Node * head = NULL; // define the linked list header as a global variable to facilitate subsequent operations on void make_list (); // create the linked list void out_list (); // output the linked list int main () {make_list (); out_list (); return 0;} void make_list () {int n; Node * p; cout <"Enter positive numbers (end with 0 or a negative number) create a linked list: "<endl; cout <endl; cin> n; while (n> 0) // enter positive numbers to create a linked list. When a positive number is input, the creation process ends {p = new Node; // create a Node p-> date = n; p-> next = Head; // the newly created node points to the head of the original linked list = p; // The head of the linked list is assigned as the newly created node. In this way, the new node is always the head of the linked list cin> n; // enter a positive number to create the next Node} return;} void out_list () {Node * p = head; cout <"the data in the linked list is:" <endl; cout <endl; while (p! = NULL) {cout <p-> date <""; p = p-> next;} cout <endl; return ;}




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.