SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct nodeType{
  5.     int data;
  6.     nodeType *link;
  7. };
  8.  
  9. int main() {
  10.  
  11.     nodeType *head, *current, *newNode;
  12.     head = NULL;
  13.     newNode = new nodeType;
  14.  
  15.     newNode -> data = 4;          //first node
  16.     newNode ->link = NULL;
  17.     head = newNode;
  18.  
  19.     current = head;
  20.     cout << current->data << endl;
  21.  
  22.     newNode = new nodeType;       // second node
  23.     newNode ->data = 9;
  24.     newNode -> link = NULL;
  25.     head -> link = newNode;
  26.  
  27.     current = head->link;
  28.     cout << current->data << endl;
  29.  
  30.     newNode = new nodeType;
  31.     newNode -> data = 1;
  32.     newNode -> link = NULL;
  33.     head->link->link = newNode;
  34.  
  35.     current = head->link->link;
  36.     cout << current ->data << endl;
  37.  
  38.     newNode = new nodeType;
  39.     newNode -> data = 3;
  40.     newNode -> link = NULL;
  41.     head ->link->link->link = newNode;
  42.  
  43.     current = head->link->link->link;
  44.     cout << current -> data << endl << endl;
  45.  
  46.  
  47.  
  48.     current = head;
  49.     while(current != NULL){
  50.         cout << current ->data << " ";
  51.         current = current ->link;
  52.     }
  53.  
  54.  
  55.  
  56.     return 0;
  57. }
RAW Paste Data
Top