结构体指针

#include
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->next=head;
	#define FOR(head,p) for(p=head->next;p->next!=head->next;p=p->next)
	p=head->next;
	FOR(head,p) { cout<<p->data<<" "; }
	return 0;
}

你可能感兴趣的:(c++,刘汝佳,DLX,结构体指针)