home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / wininet / asyncftp / clist.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-01  |  2.7 KB  |  129 lines

  1. #include <windows.h>
  2. #include <wininet.h>
  3. #include <commctrl.h>
  4. #include "comctlhd.h"
  5. #include "clist.h"
  6. #include "resource.h"
  7.  
  8.  
  9. //**********************************************************************
  10. // Clist::Clist
  11. //
  12. // Purpose: Constructor for Clist class
  13. // Parameters: None
  14. //
  15. //********************************************************************
  16.  
  17. Clist::Clist()
  18. {
  19.     head = new node;
  20.     z = new node;
  21.     head->next = z;
  22.     z->next = z;
  23.  
  24. }
  25.  
  26. //**********************************************************************
  27. // Clist::Clist
  28. //
  29. // Purpose: Destructor for Clist class
  30. // Parameters: None
  31. //
  32. //********************************************************************
  33. Clist::~Clist()
  34. {
  35.     return;
  36.  
  37. }
  38.  
  39. //**********************************************************************
  40. // Clist::remove
  41. //
  42. // Purpose: remove all the nodes associated with the class instance
  43. // Parameters: None 
  44. // Return Value: None 
  45. //
  46. //********************************************************************
  47. void Clist::remove(void)
  48. {
  49.     struct node *t = head;
  50.     while ( t!=z)
  51.     {
  52.         head = t;
  53.         t = t->next;
  54.         delete head;
  55.     }
  56.  
  57. }
  58.  
  59. //**********************************************************************
  60. // Clist::remove
  61. //
  62. // Purpose: remove a node based on key value
  63. // Parameters: 
  64. //    Lint ikey - key value
  65. // Return Value: None 
  66. //
  67. //********************************************************************
  68.  
  69. void Clist::remove(int ikey)
  70. {
  71.     struct node *tmp, *t = head;
  72.     while ( t->next !=z)
  73.     {
  74.         if (t->next->data.key == ikey)
  75.         {
  76.             tmp = t->next;
  77.             t->next = tmp->next;
  78.             delete tmp;
  79.             break;
  80.         }
  81.         t = t->next;
  82.     }
  83.  
  84. }
  85.  
  86.  
  87. //**********************************************************************
  88. // Clist::insertatend
  89. //
  90. // Purpose: Insert a new node into the linked list
  91. // Parameters: 
  92. //    LPTVNODEINFO pelem - initialization values for node data member
  93. // Return Value:  
  94. //    pointer to node elements data member
  95. //
  96. //********************************************************************
  97.  
  98. LPTVNODEINFO Clist::insertatend(LPTVNODEINFO pelem)
  99. {
  100.     struct node *t = head->next;
  101.     struct node *n = new node;
  102.     struct node *last = head;
  103.     n->data.dwAttributes = pelem->dwAttributes;
  104.     n->data.enumflag = pelem->enumflag;
  105.     n->data.hConnect = pelem->hConnect;
  106.     lstrcpy(n->data.pszSite, pelem->pszSite);
  107.     lstrcpy(n->data.pszDir, pelem->pszDir);
  108.     n->data.requestType = pelem->requestType;
  109.     n->data.prequestResult = pelem->prequestResult;
  110.     n->data.index = pelem->index;
  111.  
  112.     srand( (unsigned)GetTickCount( ) );
  113.     n->data.key = rand();
  114.  
  115.     n->next = z;
  116.     while (t!=z)
  117.     {
  118.         last = t;
  119.         t = t->next;
  120.     }
  121.     last->next = n;
  122.     return &(n->data);
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129.