C语言实现数据结构双循环链表

#include <stdio.h>
#include <stdlib.h>

typedef struct DNode{

	int data;
	struct DNode * next,*prior;
}DNode, * DLinkList;

bool InitiList(DLinkList &L){
	L= (DNode*)malloc(sizeof(DNode));
	if(L==NULL)
		return false;
	L->next=NULL;
	L->prior=NULL;
	return true;
}

//在p结点之后插入s
bool InsertList(DNode* p, DNode* s){ //为什么有的地方需要LinkList &L 而这里是*p
	if(p==NULL||s==NULL)
		return false;
	s->next = p->next;
	if(p->next!=NULL)
	p->next->prior = s;//如果是最后一个节点,p->next=NULL没有东西,就会出错

	s->prior = p;
	p->next = s;
	return true;
}
//在p之后删除节点s
bool DeletList(DNode* p, DNode* s){
	p->next = s->next;
	if(s->next!=NULL)
	s->next->prior = p; //s是最后一个元素怎么办
	free(s);
	return true;
}

void swap(int* a, int* b)
{
	int c=0;
	
	c=*a;
	*a=*b;
	*b=c;
}
void main(void){
	int x=1,y=2;
	int* a = &x;
	int* b = &y;

	swap(&x,&y);
	printf("%d%d%0x",x,y,a);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值