단일 체인 테이블의 역방향 인쇄, 머리 없는 비끝 노드 삭제, 머리 없는 체인 테이블 삽입 노드, 요셉 링

//1、 ( )
void PrintTailToHead(ListNode *pHead)
{
                ListNode *cur = pHead;
                 if(cur != NULL)
                {
                                PrintTailToHead(cur->_next);
                                printf( "%d ",cur->_data);
                }
}
//2、 
void DelNoTail(ListNode *pos)
{
                assert(pos && pos->_next );
                ListNode *next = pos->_next ;
                swap(pos->_data ,next->_data );
                pos->_next = next->_next ;
                free(next);
}
//3、 
void InsertNoHead(ListNode * pos, DataType x)
{
                ListNode *tmp = BuyNode(pos->_data );
                tmp->_next = pos->_next;
                pos->_next = tmp;
                pos->_data = x;
}
//4、 ( )
ListNode* Josephuscycle(ListNode *pHead, DataType x)
{
                ListNode *cur = pHead;
                 while(1)
                {
                                 if(cur = 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);
                }
}

좋은 웹페이지 즐겨찾기