Realize double linked list to add delete to check head tail plug middle plug in front, behind, read, can choose according to the location or by value operation, under Linux ok
/*
Doubly linked list
Disable the main () the when use
*/
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# define _VAL_WISE 1
# define _POS_WISE 0
# define _PFX 0
# define _BHD 1
//typedef struct Data {
//unsigned int UID;
//int intVal1;
//int intVal2;
//float fltVal;
//char string [50].
//void * ptr1;
//void * ptr2 will;
//} data, * pdata;
Typedef struct Dnode {
Struct Dnode FWD is *;
Struct Dnode * BWD;
Int val.
//data obj.
} dnode, * pdnode;
Pdnode init_dnode (int num);
//init a node with the "num" parts of element
Void show_dnode (pdnode p_dnode);
//printf all value forward
Void apd_dnode (pdnode p_dnode, int val_f);
//add one element at the tail
Int srh_dnode (pdnode p_dnode, int pos);
//ger a specific position 'value, pos start from 1
Int pos_dnode (pdnode p_dnode, int val_f);
//get first val_f 'position
Void inst_dnode (pdnode p_dnode, int val_f, int val_d, int method, int bora);
//insert one element to the node, val_f is the position or the target value, feature by method
//if method==_VAL_WISE, val_f act as target value, the if method==_POS_WISE
//val_f act as target position, the position of start from 1
//if bora==_BHD, new value "val_d" will be inserted behind the target value or target position
//otherwise if bora==_PFX, before
Void show_IC (pdnode p_dnode);
//show all the node value forward once, then backward once
Void rpe_dnode (pdnode p_dnode, int val_f, int val_d, int method);
//replace the node 's one value, val_f and val_d and method' s usage are same as above
Void del_dnode (pdnode p_dnode, int val_f, int method);
//delete node 's one value, val_f and val_d and method' s usage are same as above
Void dsty_dnode (pdnode p_dnode);
//free node 's all the memory
Int main (void) {
Int num=0;
Int val_d;
Printf (" input num: \ n ");
The scanf (" % d ", & amp; Num);
Pdnode p_dnode=init_dnode (num);
Show_dnode (p_dnode);
Int val_f=0;
Printf (" input a val to append \ n ");
The scanf (" % d ", & amp; Val_f);
Apd_dnode (p_dnode val_f);
Show_dnode (p_dnode);
int pos=0;
Printf (" input a pos to SRH \ n ");
The scanf (" % d ", & amp; Pos);
Printf (" val is % d \ n ", srh_dnode p_dnode, pos ());
Printf (" input a val to pos \ n ");
The scanf (" % d ", & amp; Val_f);
Printf (" pos is % d \ n ", pos_dnode (p_dnode val_f));
Printf (" input val_f (pos or val), val_d to insert_BHD \ n ");
The scanf (" % d % d ", & amp; Val_f, & amp; Val_d);
Inst_dnode (p_dnode val_f, val_d _VAL_WISE, _BHD);
Show_dnode (p_dnode);
Printf (" input val_f (pos or val), val_d to insert_PFX \ n ");
The scanf (" % d % d ", & amp; Val_f, & amp; Val_d);
Inst_dnode (p_dnode val_f, val_d _VAL_WISE, _PFX);
Show_dnode (p_dnode);
Printf (" input val_f (pos or val), val_d to replace \ n ");
The scanf (" % d % d ", & amp; Val_f, & amp; Val_d);
Rpe_dnode (p_dnode val_f, val_d _VAL_WISE);
Show_dnode (p_dnode);
Printf (" input val_f (pos or val) to delete \ n ");
The scanf (" % d ", & amp; Val_f);
Del_dnode (p_dnode val_f, _VAL_WISE);
Show_dnode (p_dnode);
//dsty_dnode (p_dnode);
Show_IC (p_dnode);
}
Pdnode init_dnode (int num) {//init
Pdnode p_head;
P_head=(pdnode) malloc (sizeof (dnode));
If (p_head==NULL) {
Printf (" out of memory when the init node \ n ");
return NULL;
}
P_head - & gt; FWD=p_head;
P_head - & gt; BWD=p_head;
Int val_f=0;
Pdnode p_temp=p_head;
Pdnode p_new;
int i=0;
For (I=0; iP_new=(pdnode) malloc (sizeof (dnode));
If (p_new==NULL) {
Printf (" out of memory when the init node \ n ");
return NULL;
}
Printf (" input val to put in the node \ n ");
The scanf (" % d ", & amp; Val_f);
P_new - & gt; Val=val_f;
P_new - & gt; FWD=p_temp - & gt; FWD.
P_new - & gt; BWD=p_temp;
P_temp - & gt; FWD - & gt; BWD=p_new;
P_temp - & gt; FWD=p_new;
P_temp=p_new;
Printf (" \ n in ");
}
//p_head - & gt; Val=num;
Return p_head;
}
Void apd_dnode (pdnode p_dnode, int val_f) {//append one element
Pdnode p_temp p_new;
P_temp=p_dnode - & gt; BWD;
P_new=(pdnode) malloc (sizeof (dnode));
If (p_new==NULL) {
Printf (" out of memory when append node \ n ");
return;
}
P_new - & gt; Val=val_f;
P_new - & gt; BWD=p_temp;
P_new - & gt; FWD=p_temp - & gt; FWD.
P_temp - & gt; FWD - & gt; BWD=p_new;
P_temp - & gt; FWD=p_new;
//p_dnode - & gt; Val++;
Printf (" append one val done \ n ");
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull