#include<iostream>
using namespace std;
typedef struct _SLINKNODE
{
unsigned short Data;
struct _SLINKNODE *Next;
}SLINKNODE;
int GetData(SLINKNODE *phead, unsigned short n, unsigned short *pData) //获得倒数第n个结点的数据
{
if (phead==0 || n==0)
{
return 1;
}
SLINKNODE *pFirst=phead;
SLINKNODE *pSecond=NULL;
for (unsigned short i=0;i< n-1; ++i)
{
if(pFirst->Next != NULL)
{
pFirst=pFirst->Next;
}
else
return 1;
}
pSecond = phead;
while (pFirst->Next != NULL)
{
pFirst=pFirst->Next;
pSecond=pSecond->Next;
}
*pData=pSecond->Data;
return 0;
}
SLINKNODE *GetLastGroupHeadOfSum(SLINKNODE *phead, unsigned short n, unsigned int sum)// pBegin...pEnd
{
if (phead != NULL || n==0)
{
return NULL;
}
SLINKNODE *pBegin=phead;
SLINKNODE *pEnd=phead;
for (unsigned int i=0;i< n-1; ++i)
{
if(pEnd->Next != NULL)
{
pEnd=pEnd->Next;
}
else
return NULL;
}
SLINKNODE *pSave;
int sum_tmp=0;
while (pEnd!=NULL)
{
sum_tmp=0;
for (unsigned short j=0;j<n;++j)
{
sum_tmp+=pBegin->Data;
pBegin=pBegin->Next;
}
if (sum_tmp == sum)
{
pSave=pBegin;
}
pBegin=pBegin->Next;
pEnd=pEnd->Next;
}
return pSave;
}
int main()
{
return 0;
}