#include <iostream>
using namespace std;
struct Node{
int value;
Node *next;
};
struct List{
Node *head;
Node *last;
};
void add_to_end(List *list,int num);
int size_of_list(List *list);
int main()
{
List list;
list.head =NULL;
int num;
while(cin>>num){
add_to_end(&list,num);
}
return 0;
}
int size_of_list(List *list){
Node *p;
int size=0;
for(p=list->head;p;p=p->next){
++size;
}
return size;
}
void add_to_end(List *list,int num){
Node *new_node=(Node*)malloc(sizeof(Node));
new_node->value=num;
new_node->next=NULL;
list->last=list->head;
if(list->last){
while(list->last->next){
list->last=list->last->next;
}
list->last->next=new_node;
}else{
list->head=new_node;
}
}
单向链表的创建
最新推荐文章于 2021-09-19 20:36:00 发布