[ create a new paste ] login | about

Link: http://codepad.org/YiSfIMEz    [ raw code | output | fork ]

C++, pasted on Jul 3:
#include <iostream>

typedef struct node {                                                               
      int data;               // will store information
      node *next;             // the reference to the next node
};  
node *head;

int printList(node *traverse) {

    while(traverse != NULL) {
        cout << traverse->data << endl;
        traverse = traverse->next;
    }
    
    return 0;
}

int main() {
    node *temp = NULL;
    node *begin = NULL;      
    for (int i = 0; i < 10; i++) {
        temp = new node;
        temp->data = i;
        if (begin == NULL) {
            begin = temp;
        }
        if (head != NULL) {
            head->next = temp;
        }
        head = temp;
        head->next = NULL;
    }
    head = begin;
    printList(head);
    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
0
1
2
3
4
5
6
7
8
9


Create a new paste based on this one


Comments: