1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
| typedef int DataType;
typedef struct Node { DataType data; struct Node *prev; struct Node *next; }linknode;
linknode *init_list(void) { linknode *head = malloc(sizeof(linknode)); if(head == NULL) return NULL; head->next = head; head->prev = head; return head; }
linknode *create_node(DataType data) { linknode *new = malloc(sizeof(linknode)); if(new == NULL) return NULL; new->next = new; new->prev = new; new->data = data; return new; }
void insert_node(linknode *new, linknode *prev, linknode *next) { prev->next = new; next->prev = new; new->prev = prev; new->next = next; }
void insert_tail_node(linknode *new, linknode *head) { insert_node(new, head->prev,head); }
void insert_head_node(linknode *new, linknode *head) { insert_node(new, head, head->next); }
bool is_empty(linknode *head) { return (head->next == head) ? true : false; }
void display_next_list(linknode *head) { if(is_empty(head)) return ; linknode *tmp = head->next; for(; tmp != head; tmp = tmp->next) { printf("%d->", tmp->data); } printf("\n"); }
void display_prev_list(linknode *head) { if(is_empty(head)) return ; linknode *tmp = head->prev; for(; tmp != head; tmp = tmp->prev) { printf("%d->", tmp->data); } printf("\n"); }
linknode *find_node(DataType data, linknode *head) { if(is_empty(head)) return NULL; linknode *tmp = head->next; for(; tmp != head; tmp = tmp->next) { if(tmp->data == data) return tmp; } return NULL; }
linknode *remove_node(linknode *dnode) { dnode->prev->next = dnode->next; dnode->next->prev = dnode->prev; dnode->prev = NULL; dnode->next = NULL; return dnode; }
bool delete_data_node(DataType data, linknode *head) { linknode *find = NULL; find = find_node(data, head); if(find == NULL) return false; remove_node(find); free(find); return true; }
void delete_node(linknode *dnode) { remove_node(dnode); free(dnode); }
void move_next_node(linknode *mnode, linknode *next) { remove(mnode); insert_node(mnode, next, next->next); }
void move_prev_node(linknode *mnode, linknode *prev) { remove(mnode); insert_node(mnode, prev->prev, prev); }
void move_d2d(int data1, int data2, linknode *head) { linknode *d1 = find_node(data1, head); linknode *d2 = find_node(data2, head); if(d1 && d2) { remove(d1); insert_node(d1, d2, d2->next); return ; } return ; }
void updata_node(int old, int new, linknode *head) { linknode *d1 = find_node(old, head); if(d1 != NULL) { d1->data = new; return ; } return ; }
|