3.3.2 单向循环链表
- 也分为带头节点和不带头节点
- 这里用带头节点的写
- 就是普通单向链表将尾结点的next指针指向头节点即可
- 关键是当循环链表为空时,头节点的next指向自己本身
.h文件:
//
// Created by iotek_chen on 2021/1/19.
//
#include <iostream>
#include <string>
using namespace std;
#ifndef LOOPBASICLINKLIST_LOOPBASLLIST_H
#define LOOPBASICLINKLIST_LOOPBASLLIST_H
class LoopBasLList {
private:
class Node{
int index;
int val;
string data;
public:
Node* next;
Node();
int getIndex() const ;
void setIndex(int ind);
int getVal() const ;
void setVal(int i);
string getData() const ;
void setData(const string& str);
};
public:
LoopBasLList();
~LoopBasLList();
bool isEmpty();
int appendNodeToList(int val, const string& data);
int