00001 00002 #include "nodelink.hh" 00003 #include "nodelist.hh" 00004 00005 NODE_LINK_LIST::NODE_LINK_LIST () 00006 { 00007 first = NULL; 00008 current = NULL; 00009 deleting_list = 0; 00010 } 00011 00012 NODE_LINK_LIST::~NODE_LINK_LIST () 00013 { 00014 NODE_LINK_LIST_ENTRY *next_entry; 00015 if (NULL != first) 00016 { 00017 current = first; 00018 while (NULL != current) 00019 { 00020 next_entry = current->next; 00021 if (NULL != current->node_link) 00022 { 00023 delete current->node_link; 00024 current->node_link = NULL; 00025 } 00026 delete current; 00027 current = next_entry; 00028 } 00029 } 00030 } 00031 00032 int 00033 NODE_LINK_LIST::add_entry (NODE_LINK * node_link_ptr) 00034 { 00035 current = new NODE_LINK_LIST_ENTRY; 00036 if (NULL == current) 00037 { 00038 return (-1); 00039 } 00040 current->next = first; 00041 current->node_link = node_link_ptr; 00042 first = current; 00043 return (0); 00044 } 00045 00046 int 00047 NODE_LINK_LIST::delete_entry (NODE_LINK * node_link_ptr) 00048 { 00049 NODE_LINK_LIST_ENTRY *temp; 00050 NODE_LINK_LIST_ENTRY *last; 00051 00052 if (NULL != first) 00053 { 00054 if (first->node_link == node_link_ptr) 00055 { 00056 temp = first->next; 00057 if (current == first) 00058 { 00059 current = temp; 00060 } 00061 delete first; 00062 first = temp; 00063 return (0); 00064 } 00065 temp = first->next; 00066 last = first; 00067 while (NULL != temp) 00068 { 00069 if (temp->node_link == node_link_ptr) 00070 { 00071 last->next = temp->next; 00072 if (current == temp) 00073 { 00074 current = temp->next; 00075 } 00076 delete temp; 00077 return (0); 00078 } 00079 else 00080 { 00081 last = temp; 00082 temp = temp->next; 00083 } 00084 } 00085 return (-1); 00086 } 00087 return (-1); 00088 } 00089 00090 NODE_LINK * 00091 NODE_LINK_LIST::first_node () 00092 { 00093 if (NULL == first) 00094 { 00095 return (NULL); 00096 } 00097 current = first; 00098 return (first->node_link); 00099 } 00100 00101 NODE_LINK * 00102 NODE_LINK_LIST::next_node () 00103 { 00104 if (NULL == current) 00105 { 00106 return NULL; 00107 } 00108 00109 current = current->next; 00110 if (NULL == current) 00111 { 00112 return NULL; 00113 } 00114 00115 return (current->node_link); 00116 }