Chinaunix首页 | 论坛 | 博客
  • 博客访问: 347210
  • 博文数量: 78
  • 博客积分: 3380
  • 博客等级: 中校
  • 技术积分: 857
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-16 19:39
文章分类

全部博文(78)

文章存档

2011年(31)

2010年(47)

分类: C/C++

2010-08-31 21:32:52

/* ************************************************************************
 *       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;
}

 
阅读(456) | 评论(0) | 转发(0) |
0

上一篇:单链表操作

下一篇:链表合并

给主人留下些什么吧!~~