C语言学习--链表
2024-10-16 11:48:49
#include "node.h"
#include<stdio.h>
#include<stdlib.h>
//typedef struct _node {
// int value;
// struct _node *next;
//} Node; int main(int agrc,char const *argv[])
{
int number;
Node * head = NULL;
do {
scanf("%d",&number);
if (number != -) {
//add to link list
Node *p = (Node*)malloc(sizeof(Node));
p->value = number;
p->next = NULL;
//finde the last
Node *last = head;
if (last) {
while (last->next) {
last = last->next;
}
last->next = p;
} else {
head = p;
}
}
}while (number != -);
return ;
}
加入LIST后
#include "node.h"
#include<stdio.h>
#include<stdlib.h>
//typedef struct _node {
// int value;
// struct _node *next;
//} Node;
typedef struct _list {
Node* head;
} List; void add(List* pList,int number);
int main(int argc,char const *argv[])
{
int number;
List list;
list.head = NULL;
do {
scanf("%d",&number);
add(&list,number);
} while (number != -); return ;
} void add(List* pList,int number)
{
while (number != -) {
//add to link-list
Node *p = (Node*)malloc(sizeof(Node));
p->value = number;
p->next = NULL;
// find the last
Node *last = pList->head;
if (last) {
while (last->next) {
//attach
last = last->next;
}
last->next = p;
} else {
pList->head = p;
}
}
}
最新文章
- MediatorPattern(中介者模式)
- [Ubuntu] 转载-使用Ubuntu修复grub
- innodB的隐式锁
- 小白日记9:kali渗透测试之主动信息收集(二)四层发现:TCP、UDP、nmap、hping、scapy
- virtualbox中ubuntu和windows共享文件夹设置
- oschina大数据开源软件
- Swift - 类的计算属性(使用get和set来间接获取/改变其他属性的值)
- phper談談最近重構代碼的感受(2)
- C++实验指导
- web api 路由规则和接收数据
- java8实战一------解决冗杂,java8真的很便利(抛砖)
- tomcat部署应用时设置context path为空的上下文路径问题
- Linux下安装jieba
- 常用的Lunix命令 记录
- [Codeforces Round #526 (Div. 2)]
- POJ 1144 Network(tarjan 求割点个数)
- ExtJS 4.2 教程-06:服务器代理(proxy)
- 如何在 Mac 上通过 Boot Camp 安装 Windows?
- Nginx upstream的5种权重分配方式【转】
- JDK源码分析(一)——ArrayList