⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linklist.cpp

📁 单链表倒序
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
struct celltype
{
	int element;
	celltype *next;
};
typedef celltype* position;
typedef celltype* DLIST;
void HEADandTAIL(position &l)
{
	l=(position)malloc(sizeof(struct celltype));
	l->element=0;
	l->next=l;
}
	
void INSERT (int x, position &p)
{
	position TMP;
	TMP=(position)malloc(sizeof(struct celltype));
	TMP->element=x;
	TMP->next=p->next;
	p->next=TMP;
}
int main()
{
	DLIST l, pst;
	int t;
	int bs[4]={5,6,7,8};
	HEADandTAIL(l);
	pst=l;
	printf("本程序链表的长度为6, 已知\n");
	for(t=0; t<4; t++)
	{
		INSERT(bs[t], pst);
		pst=pst->next;
		l->element++;
	}
	pst=l;
	for(t=0; t<l->element; t++)
	{
		printf("%d ", pst->next->element);
	    pst=pst->next;
    }
	printf("\n这是原顺序\n以下是反向后的顺序\n");
	l->next->next->next->next->next=l->next->next->next;
    l->next->next->next->next=l->next->next;
    l->next->next->next=l->next;
    l->next->next=l;
    l->next=pst;	
	pst=l;
	for(t=0; t<l->element; t++)
	{
		printf("%d ", pst->next->element);
	    pst=pst->next;
    }
	printf("\n");
	return 0;
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -