Init commit
This commit is contained in:
parent
0eb3c22ceb
commit
4413c90edc
@ -25,6 +25,9 @@
|
|||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
108A953A29878C0D005C28B4 /* DataStructure */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = DataStructure; sourceTree = BUILT_PRODUCTS_DIR; };
|
108A953A29878C0D005C28B4 /* DataStructure */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = DataStructure; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
108A953D29878C0D005C28B4 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
108A953D29878C0D005C28B4 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||||
|
108A954429878C66005C28B4 /* DoubleLinkList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoubleLinkList.h; sourceTree = "<group>"; };
|
||||||
|
108A9546298792B3005C28B4 /* CycleLinkList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CycleLinkList.h; sourceTree = "<group>"; };
|
||||||
|
108A9547298794DA005C28B4 /* CycleDoubleLinkList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CycleDoubleLinkList.h; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -58,6 +61,9 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
108A953D29878C0D005C28B4 /* main.cpp */,
|
108A953D29878C0D005C28B4 /* main.cpp */,
|
||||||
|
108A9547298794DA005C28B4 /* CycleDoubleLinkList.h */,
|
||||||
|
108A9546298792B3005C28B4 /* CycleLinkList.h */,
|
||||||
|
108A954429878C66005C28B4 /* DoubleLinkList.h */,
|
||||||
);
|
);
|
||||||
path = DataStructure;
|
path = DataStructure;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
54
DataStructure/CycleDoubleLinkList.h
Normal file
54
DataStructure/CycleDoubleLinkList.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
//
|
||||||
|
// CycleDoubleLinkList.h
|
||||||
|
// DataStructure
|
||||||
|
// 循环双链表
|
||||||
|
// Created by Noth Amor on 2023/1/30.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef CycleDoubleLinkList_h
|
||||||
|
#define CycleDoubleLinkList_h
|
||||||
|
|
||||||
|
typedef struct DNode {
|
||||||
|
int data;
|
||||||
|
struct DNode *prior, *next;
|
||||||
|
}DNode, *DLinkList;
|
||||||
|
|
||||||
|
// 初始化空的循环双链表
|
||||||
|
bool InitDLinkList(DLinkList &L) {
|
||||||
|
L = (DNode *) malloc(sizeof(DNode));
|
||||||
|
if (L == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
L->prior = L;
|
||||||
|
L->next = L;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断循环双链表是否为空
|
||||||
|
bool Empty(DLinkList L) {
|
||||||
|
return L->next == L;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环双链表在p节点之后插入s节点
|
||||||
|
bool InsertNextDNode(DNode *p, DNode *s) {
|
||||||
|
s->next = p->next;
|
||||||
|
p->next->prior = s;
|
||||||
|
s->prior = p;
|
||||||
|
p->next = s;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除p的后继节点q
|
||||||
|
bool DeleteDNode(DNode *p) {
|
||||||
|
DNode *q = p->next;
|
||||||
|
p->next = q->next;
|
||||||
|
q->next->prior = p;
|
||||||
|
free(q);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CycleDoubleLinkList_h */
|
40
DataStructure/CycleLinkList.h
Normal file
40
DataStructure/CycleLinkList.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// CycleLinkList.h
|
||||||
|
// DataStructure
|
||||||
|
// 循环单链表
|
||||||
|
// Created by Noth Amor on 2023/1/30.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef CycleLinkList_h
|
||||||
|
#define CycleLinkList_h
|
||||||
|
|
||||||
|
typedef struct LNode{
|
||||||
|
int data;
|
||||||
|
struct LNode *next;
|
||||||
|
}LNode, *LinkList;
|
||||||
|
|
||||||
|
// 初始化循环单链表
|
||||||
|
bool InitList(LinkList &L) {
|
||||||
|
L = (LNode *) malloc(sizeof(LNode));
|
||||||
|
if (L == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
L->next = L;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断循环单链表是否为空
|
||||||
|
bool Empty(LinkList L) {
|
||||||
|
return L->next == L;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断节点p是否为循环单链表的表尾节点
|
||||||
|
bool IsTail(LinkList L, LNode *p) {
|
||||||
|
return p->next == L;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CycleLinkList_h */
|
84
DataStructure/DoubleLinkList.h
Normal file
84
DataStructure/DoubleLinkList.h
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
//
|
||||||
|
// DoubleLinkList.h
|
||||||
|
// DataStructure
|
||||||
|
// 双链表
|
||||||
|
// Created by Noth Amor on 2023/1/30.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef DoubleLinkList_h
|
||||||
|
#define DoubleLinkList_h
|
||||||
|
|
||||||
|
typedef struct DNode {
|
||||||
|
int data;
|
||||||
|
struct DNode *prior, *next;
|
||||||
|
} DNode, *DLinkList;
|
||||||
|
|
||||||
|
// 初始化双链表
|
||||||
|
bool InitDLinkList(DLinkList &L) {
|
||||||
|
L = (DNode *) malloc(sizeof(DNode));
|
||||||
|
if (L == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
L->prior = NULL;
|
||||||
|
L->next = NULL;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断双链表是否为空
|
||||||
|
bool LinkListEmpty(DLinkList L) {
|
||||||
|
return L->next == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除p节点的后继节点
|
||||||
|
bool DeleteNextNode(DNode *p) {
|
||||||
|
if (p == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DNode *q = p->next;
|
||||||
|
|
||||||
|
if (q == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->next = q->next;
|
||||||
|
if (p->next != NULL) {
|
||||||
|
q->next->prior = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(q);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 销毁双链表
|
||||||
|
void DestroyDLinkList(DLinkList &L) {
|
||||||
|
while (L->next != NULL) {
|
||||||
|
DeleteNextNode(L);
|
||||||
|
}
|
||||||
|
free(L);
|
||||||
|
L = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在p节点之后插入s节点
|
||||||
|
bool InsertNextNode(DNode *p, DNode *s) {
|
||||||
|
if (p == NULL || s == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
s->next = p->next;
|
||||||
|
if (p->next != NULL) {
|
||||||
|
p->next->prior = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
s->prior = p;
|
||||||
|
p->next = s;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DoubleLinkList_h */
|
18
DataStructure/LinkList.h
Normal file
18
DataStructure/LinkList.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// LinkList.h
|
||||||
|
// DataStructure
|
||||||
|
//
|
||||||
|
// Created by Noth Amor on 2023/1/30.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef LinkList_h
|
||||||
|
#define LinkList_h
|
||||||
|
|
||||||
|
typedef struct LNode{
|
||||||
|
int data;
|
||||||
|
struct LNode *next;
|
||||||
|
}LNode, *LinkList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* LinkList_h */
|
@ -1,14 +1,16 @@
|
|||||||
//
|
|
||||||
// main.cpp
|
|
||||||
// DataStructure
|
|
||||||
//
|
|
||||||
// Created by Noth Amor on 2023/1/30.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main(int argc, const char * argv[]) {
|
using namespace std;
|
||||||
// insert code here...
|
|
||||||
std::cout << "Hello, World!\n";
|
// 静态链表
|
||||||
|
typedef struct {
|
||||||
|
int data;
|
||||||
|
int next;
|
||||||
|
} SLinkList[10];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
SLinkList s;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user