循环单链表:
#ifndef CSLTest_hpp #define CSLTest_hpp #include#include using namespace std; typedef struct CSLNode{ int data; struct CSLNode *next; }CSLNode,*CSlink; void Creat_CSlink(CSlink &L); void Print_CSlink(CSlink L); void Print2_CSlink(CSlink L); //将CSlink链表1链接在CSlink链表2之后,形成的新链币仍然为CSlink CSlink Merge_CSlink(CSlink &A,CSlink &B); //每次循环找到单链表中最小值删除,直到链表长度为0 void Del_Min(CSlink &L); #endif
#include "CSLTest.hpp"
//尾插法
void Creat_CSlink(CSlink &L){
L = (CSlink)malloc(sizeof(CSLNode));
CSLNode *p = L;
int x;
cout<<"输入CSL链表中的数据,-1结束"<>x;
while (x!=-1) {
CSLNode *s =new CSLNode;
s->data =x;
p->next = s;
p = s;
cin>>x;
}
p->next = L;
}
//打印
void Print_CSlink(CSlink L){
CSLNode *p = L;
while (p->next!=L) {
p=p->next;
cout<data<<" ";
}
cout<next!=L) {
p=p->next;
cout<data<<" ";
}
x++;
}
cout<next!=A) {
p=p->next;
}
q = B;
while (q->next!=B) {
q=q->next;
}
p->next = B->next;
q->next = A;
return A;
}
//
void Del_Min(CSlink &L){
CSLNode *p,*pre,*min,*minpre;
while (L->next!=L) {
p=L->next;
pre=L;
min = p;
minpre=pre;
while(p!=L){
if (p->datadata) {
min = p;
minpre = pre;
}
pre = p;
p = p->next;
}
cout<data<<" ";
minpre->next = min->next;
free(min);
}
free(L);
}
循环双链表
#ifndef CBLTest_hpp #define CBLTest_hpp #include#include using namespace std; typedef struct CBLNode{ int data; struct CBLNode *next,*piror; }CBLNode,*CBlink; //创建CBL void Creat_CBlink(CBlink &L); //打印 void Print_CBlink(CBlink L); //判断循环双链表是否对称 bool Judge_Symmetry(CBlink L); #endif
#include "CBLTest.hpp"
void Creat_CBlink(CBlink &L){
L = (CBlink)malloc(sizeof(CBLNode));
L->next =L;
L->piror = L;
CBLNode *p =L;
int x;
cout<<"向CBL链表中输入数据,输入-1时结束"<>x;
while (x!=-1) {
CBLNode *s = new CBLNode;
s->data = x;
s->next =p->next;
p->next =s;
s->piror = p;
p = s;
cin>>x;
}
p->next = L;
L->piror =p;
}
//
void Print_CBlink(CBlink L){
CBLNode *p =L->next;
while (p!=L) {
cout<data<<" ";
p=p->next;
}
cout<next;
CBLNode *q =L->piror;
while (p!=q&&q->next!=p) {
if (p->data!=q->data) {
cout<<"此循环双链表不对称!"<next;
q=q->piror;
}
}
cout<<"此循环双链币对称!"<



