weidagang2046的专栏

物格而后知致
随笔 - 8, 文章 - 409, 评论 - 101, 引用 - 0
数据加载中……

Partially Revert Linked List

Partially Revert Linked List

Problem: partially revert a linked list

Given a HEAD pointer to a linked list and an OFFSET pointer pointing to a node in the linked list. You are asked to write a C/C++ subroutine to revert the part of the list from HEAD to OFFSET:

 

You are NOT allowed to use recursion. Please follow the definition of the type and function as shown below:

 

typedef struct _Node

...{

    int value;

    struct _Node* next;

}Node;

 

Node* Revert(Node* head, Node* offset)

...{

    //Your code here. Return the head of new linked list.

}

 

Exchange Nodes

Problem: Exchange the odd and even nodes in a linked list.

 

Given a "head" pointer to a linked list. You are asked to write a C/C++ function to exchange the odd and even nodes in the linked list. For example:

Please follow the type and function definitions below:

 

typedef struct _Node

...{

    int value;

    struct _Node* next;

}Node;

 

void ExchangeNodes(Node** phead) //note: phead is of Node** type

...{

    //your code here.

}

posted on 2005-10-27 21:04 weidagang2046 阅读(299) 评论(0)  编辑  收藏 所属分类: Others


只有注册用户登录后才能发表评论。


网站导航: