Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. class node{
  7.     public:
  8.         int value;
  9.         node *ptr;
  10.         };
  11.    
  12. node list;
  13. node empty;
  14. node empty2;
  15.  
  16. void CreateList(node &head){
  17.     head.value = -1;
  18.     head.ptr   = NULL;
  19.     }
  20.  
  21. void AddEntry(node &head, int value){
  22.     static node ThisNode;
  23.    
  24.     head.value += 1;
  25.  
  26.     if(head.value == 0){
  27.         head.ptr = new node;
  28.         head.ptr->value = value;
  29.         return;
  30.     }else{
  31.         ThisNode = head;
  32.         for(int i = 0; i < head.value; ++i){
  33.                 ThisNode = *(ThisNode.ptr);
  34.                 }
  35.         ThisNode.ptr = new node;
  36.         ThisNode.ptr->value = value;
  37.         ThisNode.ptr->ptr   = NULL;
  38.         return;
  39.         }
  40.     }
  41.  
  42. node GetEntry(node head, int entry){
  43.     static node ThisNode;
  44.    
  45.     ThisNode = head;   
  46.     for(int i = 0; i <= entry; ++i){
  47.             ThisNode = *(ThisNode.ptr);
  48.             }
  49.     return ThisNode;
  50.     }
  51.  
  52. int main(){
  53.    
  54.    
  55.     CreateList(list);
  56.    
  57.     AddEntry(list, 6); //0
  58.     empty = GetEntry(list, 0);
  59.     printf("%d\n", empty.value);
  60.    
  61.     AddEntry(list, 4); //1
  62.     empty2 = GetEntry(list, 1);
  63.     printf("%d\n", empty2.value);  
  64.    
  65.     //printf("%d\n", list.value);
  66.        
  67.     system("pause");
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement