// k.cpp :
//
#include "stdafx.h"
typedef struct _node
{
int v;
_node* pNext;
}NODE;
NODE* head = NULL;
void init_list()
{
NODE* pCur;
int i = 0;
while( i < 100)
{
if (head == NULL)
{
head = new NODE;
head->v = i++;
head->pNext = NULL;
pCur = head;
}
else
{
pCur->pNext = new NODE;
pCur = pCur->pNext;
pCur->v = i++;
pCur->pNext = NULL;
}
}
}
void destory_list()
{
NODE* pCur = head;
NODE* pPre = head;
while(pCur != NULL)
{
pPre = pCur->pNext;
delete pCur;
pCur = pPre;
}
}
void print_list()
{
NODE* pCur = head;
for (int i=0; i< 100; i++)
{
printf("%d ",pCur->v);
pCur = pCur->pNext;
}
printf("\n");
}
void print_k(int k)
{
NODE* pCur = head;
int i = 0;
while(pCur != NULL && i < k)
{
pCur = pCur->pNext;
i++;
}
if ( i > k )
{
return;
}
NODE* pCur1 = head;
while(pCur != NULL)
{
pCur = pCur->pNext;
pCur1 = pCur1->pNext;
}
if (pCur1 != NULL)
{
printf("k[%d] val[%d]\n", k, pCur1->v);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
init_list();
print_list();
print_k(0);
print_k(1);
print_k(30);
print_k(100);
destory_list();
return 0;
}