/*
单链表的建立、测长和打印
*/
#include<iostream>
#include<vector>
using namespace std;
typedef struct student
{
int data;
struct student *next;
}Node;
// 创建
Node *Creat()
{
Node *head = (Node*)malloc(sizeof(Node));
int cycle = 1;
Node *p = head;
Node *q;
int x;
while(cycle)
{
cin>>x;
if(x != 0)
{
q = (Node *)malloc(sizeof(Node));
q->data = x;
cout<<q->data;
p->next = q;
p = q;
}
else
cycle = 0;
}
head = head->next;
p->data = NULL;
return head;
}
// 单链表的测长
int Length(Node *head)
{
int count = 0;
Node *p = head;
while(p != NULL)
{
p = p->next;
count++;
}
return count;
}
int main()
{
}
单链表的建立、测长和打印
最新推荐文章于 2022-03-09 17:19:05 发布