无头节点的双向循环链表

#include 
using namespace std;
struct Node{
    int data;
    Node *next,*pre;
};
Node* CreatList(){
    Node *head=new Node,*p=head;   
    int data;
    if(cin>>data){
        head->data=data;
        head->next=head->pre=head;
    }
    while(cin>>data){
        Node *q=new Node;
        q->data=data;
        q->pre=p;
        p->next=q;
        p=q;
    }
    p->next=head;
    head->pre=p;
    return head;
}
void DeleteList(Node* head, int x){
    Node *p=head,*q;
    for(int i=1;inext;
    q=p->next;
    p->next=q->next;
    q->next->pre=p;
    delete q;
}
void show(Node* head){
    Node* p=head;
    if(!p) return;
    cout<data<<' ';
    p=p->next;
    while(p!=head){
        cout<data<<' ';
        p=p->next;
    }
}
void reshow(Node* head){
    Node* p=head;
    if(!p) return;
    cout<data<<' ';
    p=p->pre;
    while(p!=head){
        cout<data<<' ';
        p=p->pre;
    }
}
int main(){
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    Node *head=CreatList();
    DeleteList(head,1);
    show(head);
    cout<

你可能感兴趣的:(无头节点的双向循环链表)