/* ************************************************************************
* Filename: loopLink.c
* Description:
* Version: 1.0
* Created: 08/31/2010 08:18:12 PM
* Revision: none
* Compiler: gcc
* Author: chengbin_liu,
* Company:
* ************************************************************************/
#include
#include
#include
typedef struct node
{
int data;
struct node *next;
}node;
node *node_create(int n)
{
node *pRet=NULL;
if(0!=n)
{
int n_idx=1;
node *p_node=NULL;
p_node=new node[n];
if(NULL==p_node)
{
return NULL;
}
else
{
memset(p_node,0,n*sizeof(node));
}
pRet=p_node;
while(n_idx {
p_node->data=n_idx;
p_node->next=p_node+1;
p_node=p_node->next;
n_idx++;
}
p_node->data=n;
p_node->next=pRet;
}
return pRet;
}
int main()
{
int n=20;
int m=6;
node *pList=NULL;
node *pIter=NULL;
pList=node_create(n);
pIter=pList;
m%=n;
while(pIter !=pIter->next)
{
int i=1;
for(;i {
pIter=pIter->next;
}
printf("%d",pIter->next->data);
pIter->next=pIter->next->next;
pIter=pIter->next;
}
printf("%d\n",pIter->data);
delete[] pList;
return 0;
}
阅读(485) | 评论(0) | 转发(0) |