链表-数据结构-C语言

链表:线性表的链式表示和实现

单链表的定义和表示

**特点:**用一组任意的存储单元(可以连续,也可以不连续)存储线性表的数据元素。
结点(node):①数据域:存储数据元素信息;②指针域:存储直接后继存储位置的域。【单链表中最后一个结点指针为null】

struct Node{
	int val;
	struct Node *next;
}

创建链表:

struct Node*creatList(){
	 struct Node *pHead=(struct Node*)malloc(sizeof(struct Node));
	 pHead->next=NULL;
	 return pHead;
}

创建结点:

struct Node*creatList(int data){
	struct Node *newNode=(struct Node *)malloc(sizeof(struct Node));
	newNode=data;
	newNode->next=NULL;
}

链表打印:

void printList(struct Node *HeadList){
	struct Node *pPrint=HeadList->next;
	while(pPrint){
		printf("%d",&pPrintf->val);
		pPtint=pPrint->next;
	}
	printf("\n");
}

头插法:

void insertList(int data){
	struct Node*newNode=creatList(data);
	newNode->next=pHead->next;
	pHead->next=newNode;	
}

尾插法:

void insert(int data){
	struct Node*newNode=creatList(data);
	pHead->next=newNode;
	newNode->next=NULL;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值