单链表的建立、测长和打印

来源:互联网 发布:2017高送转 数据宝 编辑:程序博客网 时间:2024/05/22 20:37

#include<iostream>


using namespace std;


typedef struct St

{

int data;

Node * next;

}Node;


Node* Create()

{

Node* q= (Node*)malloc(sizeof(Node));

        int x;

        Bool circle = True;

while(circle)

{

cin>>x;


  if(x != 0)

{

Node* p = (Node*)malloc(sizeof(Node));

p->data = x;

                      p->data = x;

      q->next =p;

        q=p;

}

  else

{

circle = False;

  }  

}

       p->next = NULL;

return head;

}

int length(Node* head)

{

Node * p = head;

int  x = 0;

       while(p->next != NULL)

{

         x++;

p = p->next;

}

     return x; 

}

void Print(Node* head)

{

Node * p =head->Next;

while(NULL != p)

{

cout<<p->data;

p = p->next;

}


}

0 0