Academic leave Project 1-Dynamic linked list Experience 3

Source: Internet
Author: User



(3) Write the function delete_first_node () to delete the first node in the list.

#include <iostream>using namespace std;struct node{int data;  Node data struct node *next; Point to next node};    Node *head=null;   Define the list header as a global variable, so that you can manipulate void make_list () later;    Establish a linked list void out_list ();    Output list void Delete_first_node (); int main () {make_list ();    Out_list ();    Delete_first_node ();    Out_list (); return 0;}    void Make_list () {int n;    Node *p,*q;    cout<< "Enter several positive numbers (ending with 0 or a negative number) to create a linked list:";    cin>>n;  while (n>0)//Enter several positive numbers to create a linked list, enter a non-positive number when the build process ends {p=new Node;        New node p->data=n;.        p->next=null;  if (head==null) head=p;        Place the node of the first entered number at the end of the list else q->next=p;        Q=p;  cin>>n; Enter next number, prepare to create next node} return;    void Out_list () {Node *p=head;    cout<< "The data in the list is:" <<endl;        while (p!=null) {cout<<p->data<< "";    p=p->next;    } cout<<endl; return;}    void Delete_first_node () {node *p=head; if (p!=null)//Delete first Node {       Head = p->next;    Delete p;    } cout<< "after delete" <<endl; return;}

Operation Result:

Summary of Knowledge points:

After deleting a node, output the node value to zero directly.

Learning experience:

Good study Day Day up

Academic leave Project 1-Dynamic linked list Experience 3

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.