Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

linkedlist in c++

/* Initialize nodes */
struct node *head;
struct node *one = NULL;
struct node *two = NULL;
struct node *three = NULL;

/* Allocate memory */
one = malloc(sizeof(struct node));
two = malloc(sizeof(struct node));
three = malloc(sizeof(struct node));

/* Assign data values */
one->data = 1;
two->data = 2;
three->data=3;

/* Connect nodes */
one->next = two;
two->next = three;
three->next = NULL;

/* Save address of first node in head */
head = one;
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #linkedlist
ADD COMMENT
Topic
Name
6+9 =