--1 list

Create an empty three nodes, the next pointer of the three series with the node address into a single linked list

 

#include <iostream>

using namespace std;

struct Node {
    int data;
    Node* next;
};

void printList(Node* n)
{
    while (n != NULL)
    {
        cout << n->data << " ";
        n = n->next;
    }
}

int main ()
{
    Node* head = new Node();
    Node* second = new Node();
    Node* third = new Node();

    head->data = 1;
    head->next = second;

    second->data = 2;
    second->next = third;

    third->data = 3;
    third->next = NULL;

    printList(head);

    return 0;
}

 

Guess you like

Origin www.cnblogs.com/strive-sun/p/12665262.html