Building a linked list in C++

#include<iostream.h>

typedef struct item {
   int val;
   item * next;
} item;

int main() {
   item * head = NULL;
   int i;
   for(i=1;i<=10;i++) {
      item * curr = new item;
      curr->val = i;
      curr->next  = head;
      head = curr;
   }
   while(head) {
      cout << head->val << " ";
      head = head->next ;
   }
   return 0;
}

Next note in series

Back to index