关于双向链表的基本建立

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#pragma warning (disable:4996)

typedef int SLDatatype;
//结点

typedef struct SListNode
{
	struct SListNode* prev;
	SLDatatype data;
	struct SListNode* next;
}SListNode;
 //一个双向链表初定义
void InitdoubleList(SListNode** firstnode)
{
	(*firstnode) = BuydoubleSList(0);
	(*firstnode)->next = (*firstnode);
	(*firstnode)->prev = (*firstnode);
}

//购买一个双向链表
SListNode* BuydoubleSList(SLDatatype x)
{
	SListNode* newnode = (SListNode*)malloc(sizeof(SListNode));
	if (newnode == NULL)
	{
		printf("建立失败!\n");
		assert(newnode);
	}
	newnode->next = NULL;
	newnode->prev = NULL;
	newnode->data = x;
	return newnode;
}

//尾插
void pushbackdouble(SListNode**head, SLDatatype x)
{
	assert(*head);
	SListNode* tail = (*head)->prev;
	SListNode* newnode = (SListNode*)malloc(sizeof(SListNode));
	if (newnode == NULL)
	{
		printf("建立失败!\n");
		assert(newnode);
	}
	newnode->next = NULL;
	newnode->prev = NULL;
	newnode->data = x;


	tail->next = newnode;
	newnode->prev = tail;

	newnode->next = *head; 
	(*head)->prev = newnode;
}
//尾删
void popback(SListNode* head)
{
	assert(head);
	SListNode* tail = head->prev;
	SListNode* tailprev = tail->prev;
	
	tailprev->next = head;
	head->prev = tailprev;
	free(tail);
	tail=NULL;
}
//头插
void pushfront(SListNode**head, SLDatatype x)
{
	assert(*head);
	assert(*head->next != head);
	SListNode *first = head->next;
	SListNode *second = first->next;
	phead->next = second;
	second->prev = head;
	free(first);
}
//头删
void popfront(SListNode**head)

//双向链表的打印
void printfList(SListNode* head)
{
	assert(head);
	SListNode* cur = head->next;
	while (cur != head)
	{
		printf("%d",cur->data);
		cur = cur->next;
	}
}

int main()
{
	SListNode* head = NULL;
	InitdoubleList(&head);

	system("pause");
	return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值