“循环双链表”实际代码宣布实现【物联网1132-11】


循环链表和双链表的结合就是循环双链表,代码经过连日奋战终于宣布大功告成【大神请走开】


#include<iostream>
using namespace std;

template<class T>
struct Student
{
	T data;
	Student<T> * prior,* next;
};

template<class T>
class LinkList
{
public:
	LinkList();
	LinkList(T a[],int n);
	void Insert(T h,T x);
	T Delete(T y);
	void PrintList1(T u,T o);
	void PrintList2(T h,T l);
private:
	Student<T> * first;
};

template<class T>
LinkList<T>::LinkList()
{
	first=new Student<T>;
	first->next=first;
	first->prior=first;
}

template<class T>
LinkList<T>::LinkList(T a[],int n)
{
	first=new Student<T>;
	Student<T> *k = first,*s;
	int i;
	for(i=0;i<n;i++)
	{
		s=new Student<T>;
		s->data=a[i];
		k->next=s;
		(k->next)->prior=k;
		s->next=first;
		first->prior=s;
		k=s;
	}
}

template<class T>
void LinkList<T>::Insert(T h,T x)
{
	Student<T> *p = first , *s;
	while(p->data!=h)
	{
		p=p->next;
	}
		s=new Student<T>;
		s->data=x;
		s->prior=p;
		s->next=p->next;
		p->next->prior=s;
		p->next=s;
}

template<class T>
T LinkList<T>::Delete(T y)
{
	Student<T> *p =first;
	while(p->data!=y)
	{
		p=p->next;
	}
		(p->prior)->next=p->next;
		(p->next)->prior=p->prior;
	return 0;
}

template<class T>
void LinkList<T>::PrintList1(T u,T o)
{
	Student<T> *p = first->next;
	while(p->data!=u)
	{
		while((p->next)->data!=o)
		{
			cout<<p->data<<" ";
			p=p->next;
		}
		break;
	}

	cout<<endl;
}

template<class T>
void LinkList<T>::PrintList2(T n,T l)
{
	Student<T> *p = first->prior;
	while(p->data!=n)
	{
		while((p->prior)->data!=l)
		{
			cout<<p->data<<" ";
			p=p->prior;
		}
		break;
	}
	cout<<endl;
}

void main( )  
{  
	int score[6]={10,20,40,50,60,70};  
    LinkList<int>ScoreList(score, 6);
	cout<<"follow the order"<<endl;
	ScoreList.PrintList1(70,10);
	cout<<"out of the order"<<endl;
	ScoreList.PrintList2(10,70);
	cout<<"-----------------------------"<<endl;
	ScoreList.Insert(20,30);
	cout<<"follow the order"<<endl;
	ScoreList.PrintList1(70,10);
	cout<<"out of the order"<<endl;
	ScoreList.PrintList2(10,70);
	cout<<"-----------------------------"<<endl;
	ScoreList.Delete(50);
	cout<<"follow the order"<<endl;
	ScoreList.PrintList1(70,10);
	cout<<"out of the order"<<endl;
	ScoreList.PrintList2(10,70);
}



“循环双链表”代码实现时出现了的问题:【大神请走开】

1、不会灵活运用创建的“头结点”

2、错以为还有“NULL”,出现循环不断

3、对于创建链表时计算机所要做出的操作不了解,导致代码混乱

4、想要实现的功能没在上下文作出联系


“循环双链表”代码实现后的心得:【大神请走开】

1、有些事情,真的,如果你不去做,你完全不会知道这当中到底会出现什么事情

2、辛苦总会有回报的,一步一个脚印慢慢来,不要自以为是

3、对于问题的思考往往比问题本身的价值还要高

4、谢谢明哥


【物联网1132-11】



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值