#include<iostream>
#include<fstream>
using namespace std;
//链表结构
struct Node{
int data;
Node *next;
};
Node *head;
Node *create(int &n)
{//创建链表
ifstream cin("content.txt");
Node *curr;
head=NULL;
for(int i=0;i<n;i++)
{
curr=new Node;
cin>>curr->data;
curr->next=NULL;
cout<<" 第"<<i+1<<"个数据是"<<curr->data<<endl;
if(head==NULL)
{
head=curr;
}
else{
curr->next=head;
head=curr;
}
cout<<curr<<" "<<curr->data<<" "<<curr->next<<endl;
}
cout<<endl;
return head;
}
void show(Node *head)
{//打印链表
cout<<"list:head="<<head<<endl<<endl;
while(head!=NULL){
cout<<head->data<<" ";
head=head->next;
};
}
//验证head前面的值 发现show只是作用在head的拷贝上,并没有改变head的值
void main()
{
ifstream cin("in.txt");
int n;
cout<<head<<endl;
cout<<"input n:";
cin>>n;
show(create(n));//show后的head值跟create后head的值相等
cout<<head;
}