Chinaunix首页 | 论坛 | 博客
  • 博客访问: 59999
  • 博文数量: 21
  • 博客积分: 1440
  • 博客等级: 上尉
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-23 14:58
文章分类

全部博文(21)

文章存档

2008年(21)

我的朋友
最近访客

分类: C/C++

2008-04-25 19:20:27

强大的链表
题目:
/*************************************************
有一个数组a[1000]存放0--1000;要求每隔二个数删掉一
个数,到末尾时循环至开头继续进行,求最后一个被删
掉的数的原始下标位置。

以7个数为例:

{0,1,2,3,4,5,6,7} 0-->1-->2(删除)-->3-->4-->5(删除)-->6-->7-->0(删除),
如此循环直到最后一个数被删除。

我执行了1000次实验,结果如下

执行程序时间为:881 clocks
请按任意键继续. . .
**************************************************/
#include
using namespace std;
#define null 0

struct node
{
int data;
node* next;
};

int
main()
{
int startTime = clock();
int countProject;
for(countProject=0;countProject<1000;countProject++){
// ***********************
node* head=new node;
head->data=0;
head->next=null;
node* p=head;
for(int i=1;i<1000;i++)
{
node* tmp=new node;
tmp->data=i;
tmp->next=null;
head->next=tmp;
head=head->next;
}
head->next=p;
//创建循环链表
// ***********************
while(p!=p->next)
{
p->next->next=p->next->next->next;
p=p->next->next;
}
//cout<data< }
cout<<"执行程序时间为:"< system("pause");
return 0;
}




阅读(424) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~