链表的输出程序出现问题

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct Node{
    int data;
    Node *next;
};
Node *p,*r,*head;
int main(int argc, char** argv) {
    int x;
    head=new(Node);
    r=head;
    cin>>x;
    while(x!=-1){
        p=new(Node);
        p->data=x;
        r->next=p;
        p->next=NULL;
        r=p;
        cin>>x;
    } 
//************************链表输出1***************************//
    p=head->next;   
    do{
        cout<<p->data<<' '; 
        p=p->next; 
    }
    while(p->next!=NULL);
    cout<<p->data<<endl;  
    system("pause");  
//************************链表输出2***************************//
    p=head->next;   
    do{
        cout<<p->data<<' '; 
        p=p->next; 
    }
    while(p->data!=-1);  
    system("pause");  
    return 0;
}

请问一下上面在输出链表时,如果用1那段程序就没问题但是用2那段程序就会有问题(运行后return的数据异常)

1没问题??? cout<data<<' ';算什么???
while(p->data!=-1);
你这哪有p->data值为-1的操作啊?怎么可以用-1作为判断条件呢?