Advertisement
Guest User

Untitled

a guest
Jan 31st, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include<iostream>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9.     int key;
  10.     Node *next;
  11. };
  12.  
  13. Node *head;
  14.  
  15. //error
  16. void error(char *s)
  17. {
  18.   cout << s << endl;
  19.   exit(1);
  20. }
  21.  
  22. //add Node (front)
  23. void add_front(int info)
  24. {
  25.   Node *tmp;
  26.  
  27.   tmp = new Node;
  28.   if (tmp == NULL)
  29.     error("add_front: out of memory");
  30.   tmp->key = info;
  31.   tmp->next = head;
  32.   head = tmp;
  33. }
  34.  
  35. //print Nodes
  36. void print()
  37. {
  38.   Node *pos;
  39.  
  40.   pos = head;
  41.   while(pos != NULL)
  42.   {
  43.     cout << pos->key << "\t";
  44.     pos = pos->next;
  45.   }
  46.   cout << endl;
  47. }
  48.  
  49. void removeNode(int key)
  50. {
  51.     Node *pos;
  52.     pos = head;
  53.  
  54.     while(pos != NULL)
  55.     {
  56.         if(pos->key == key)
  57.         {
  58.             //TODO: let the pointer if the las Node point to this->next Node       
  59.         }          
  60.  
  61.         pos = pos->next;
  62.     }
  63.    
  64. }
  65.  
  66.  
  67.  
  68. int _tmain(int argc, _TCHAR* argv[])
  69. {
  70.  
  71.      Node *p;
  72.  
  73.      add_front(3);
  74.      add_front(2);
  75.      add_front(1);
  76.      add_front(0);
  77.  
  78.      removeNode(1);
  79.  
  80.      print();
  81.    
  82.  
  83.     char f;
  84.     cin >> f;
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement