//如有不“善”,请私聊(毕竟我是蒟蒻)
/*单链表
一、定义
struct Node{
int data;
Node *next;
};
Node *p;
特殊赋值 int *p=NULL; 初始化,赋值空,不指向任何单元
p=NULL;
p= new Node; 动态申请p的方法
二、单链表的使用*/
#include<iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
Node *head,*p,*r;
int x;
int main()
{
cin>>x;
head=new Node;//申请头节点
r=head;
while(x!=-1)
{
p=new Node;
p->data=x;
p->next=NULL;
r->next=p;
r=p;
cin>>x;
}
p=head->next;
while(p->next!=NULL)
{
cout<<p->data<<' ';
p=p->next;
}
cout<<p->data<<endl;
return 0;
}
三、一维数组