C + + Implementation of data structure program plus diagram analysis of single linked list insert and delete operation

Source: Internet
Author: User

The following figure shows the basic structure of a single linked list:

The head pointer is the header of the list, pointing to the first node, the next pointer field for each node points to the next node, and the last node's next pointer field is NULL, shown in 0.

The following first look at the program (stack of the chain store implementation, another implementation point here) and the corresponding output (note that the output before the linked list inversion (see "Single linked list inversion", otherwise the program after the while loop output order is 250,200,100), followed by the analysis of the program:

* Linkedlist.h * *
#ifndef Linkedlist_h
#define Linkedlist_h
typedef struct node *link;
struct node
{
unsigned char item;
Link next;
};
Link make_node (unsigned char item);
void Free_node (link p);
Link search (unsigned char key);
void Insert (link p);
void Deletep (link p);
void Traverse (void (*visit) (link);
void reverse (void);
void Destroy (void);
void push (link p);
Link pop (void);
#endif

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.