构建一个大小已知的链表
作者:
zjh3029 | 来源:发表于
2018-08-12 15:30 被阅读0次#include <iostream>
using namespace std;
struct node
{
int data;
int length;
node *pnext;
node(int inp,int inpl)
{
if (inpl<0)
{
return;
}
data = inp;
length = inpl;
pnext = new node(inp, inpl - 1);
}
};
int main()
{
node *poi1 = new node(1,10);
node *poi2 = poi1;//将poi1保存的地址给了poi2
for (int i = 0; i < 10; i++)
{
poi1->data = i*5;
poi1=poi1->pnext;
}
poi1->data = -1;
poi1->pnext = nullptr;
for (int i = 0; i < 8; i++)
{
cout << poi2->data << endl;
poi2 = poi2->pnext;
}
system("pause");
delete poi1;
return 0;
}
本文标题:构建一个大小已知的链表
本文链接:https://www.haomeiwen.com/subject/exvsbftx.html
网友评论