Single chain (linux c)

  Because before this one on the list has been reversed memory is unclear, now sum up the review, as long as the review is to understand the pointer address operation, the structure definition.

  Method 1: The method to obtain forward runs, the node then taken out from the front into the front side; three steps (see particularly FIG decomposition)

  <A> a first digital node and the first head is disconnected, then the last received list

  <Two> method according to the upper side and the rest of the nodes in the list one by one into the front

  <Three> until all nodes End plug, and then connect the new head and the head node

  The first complete reversal code. . The list is stored in the number 15

  

  

void fanxu (* List the plist) 

  { 

  // mark the first three nodes need 

  List * = pwei the plist; 

  List * = plist- per> pNext; 

  List * PTEMP = NULL; 

  the while (! pwei-> pNext = NULL) 

  { 

  pwei pwei- => pNext; 

  } 

  the while (! = pwei per) 

  { 

  PTEMP = per; // always labeled second node 

  per = per-> pNext; 

  // first head of the list should cut off 

  IF (pwei-> == pNext NULL) 

  { 

  pwei -> pNext = PTEMP; 

  PTEMP-> pNext = NULL; // broken 

  } 

  the else 

  { 

  PTEMP -> pNext = pwei-> pNext; // forward runs 

  pwei -> pNext = PTEMP; // then a tail pointer to 

  } 

  the plist -> = per pNext ; // to print display, you can save 

  printf ( " per-jietou - ********************************* ************************************************** ***** \ the n- " ); 

  ShowList (plist); 

  plist -> pNext = pwei; // to print display, you can save 

  printf ( " pwei-jietou - ************ ************************************************** ************************* \ the n- ");

  showlist(plist);

  printf("\n\n\n");

  }

  plist->pnext=per;

  }

 

  

  Step: <a> a first digital node and the first head is disconnected, then the last received list

  Step: <two> method according to the upper side and the rest of the nodes in the list one by one into the front

  ………

  The third step: <three> until all nodes End plug, and then connect the new head and the head node

  ########################################################################################

Method 2: Improvement simplified (to create a new flag) in the method 1 is understood that the while the primary (p) is to determine the address of the node p, p = q between the address re-assignment

  <1> define a new node is inserted down the first three bits of the node flag pq pr to the list;

  <Two> then a new node is inserted behind the flag, the same method of interpolation nodes behind

  <Three> before the new flag bit is connected to the first node plug after completion of printing

  ****************************************************************************************************************

  

void fanxu_gao (* List the plist) 

  { 

  List * PR; 

  List * P = plist-> pNext; 

  List * Q = NULL; 

  the plist -> pNext = NULL; 

  the while (P) 

  { 

  PR = p-> pNext; // records two address 

  p -> pNext = q; 

  q = p; // can be understood to q and p reassigning a new address 

  p = PR; // tag second addresses 

  the plist -> pNext = q; // print display, you can not 

  printf ( " qqqqqqqqqqqqqqqqqg ############################################ # \ the n- "); 

  ShowList (the plist); 

  the plist -> P = pNext; // print can not display 

  the printf ( " ppppppppppppppppppppz ########################## ################### \ n- " ); 

  ShowList (the plist); 

  the printf ( " \ n-\ n-\ n- " ); 

  } 

  the plist -> pNext = Q; 

  }

 

  ************************************************************************************************************************

  <1> define a new node is inserted down the first three bits of the node flag pq pr to the list;

  <Two> then a new node is inserted behind the flag, the same method of interpolation nodes behind

  <Three> before the new flag bit is connected to the first node plug after completion of printing

  ***************************************************************************************************************************

Finally, to share some information about the list of possible further reference

Singly linked list
http://www.makeru.com.cn/live/5413_1924.html?s=45051

Fun C language list
http://www.makeru.com.cn/live/1392_338.html?s=45051

Pointer
http://www.makeru.com.cn/live/1392_238.html?s=45051

Guess you like

Origin www.cnblogs.com/8734ujn/p/11583796.html