Reverse printing of single linked list, delete headless non-tail node, headless list insertion node, Joseph Ring

Source: Internet
Author: User

1. Reverse Print List (recursive) void printtailtohead (listnode *phead) {                 ListNode *cur = pHead;                  if (Cur != NULL)                  {                                  printtailtohead (Cur->_next);                                  printf (  "%d ", Cur->_data) ;                 }}//2, Delete a non-tailed node in a headless list Void delNoTail (Listnode *pos) {                 assert (pos && pos->_next );                 listnode *next = pos->_next  ;                swap ( pos->_data ,next->_data );                 pos->_next = next->_next ;                 free (next);} 3. Insert a node void insertnohead (listnode * pos, datatype x) {    before the non-head node of the headless list.              ListNode *tmp =  Buynode (pos->_data );                tmp->_next = pos->_next;                 pos->_next =  tmp;                pos- >_data = x;} 4. Joseph Ring Problem (assumed to be a circular single-linked list) listnode* josephuscycle (listnode *phead, datatype x) {                 listnode *cur =  pHead;                  while (1)                  {                                  if (CUR =&NBsp;cur->_next )                                  {                                                    return cur;                                  }                                  DataType m = x;                                   while (--x)                                   {                                                  cur = cur- >_next ;                                 }                                  listnode *next = cur->_next ;                                  swap (cur->_data ,next- >_data);                                 cur->_next  = next->_next ;                                  free (Next);                 }}


Reverse printing of single linked list, delete headless non-tail node, headless list insertion node, Joseph Ring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.