当前位置:网站首页>Linked Storage
Linked Storage
2022-06-23 06:25:00 【lascyb】
#define TRUE 1
#define ERROR 0
#define MAX_SIZE 100
#define OK 1
/** Chain store
* 1、 node : Data fields , Pointer fields form a node
* 2、 Linked list :n Nodes consist of pointer chains to form a linked list
* 3、 Single chain list 、 Double linked list 、 Circular linked list
*
* 4、 No leading node
* 5、 Leading node
* 6、 Sequential access
* */
class LianList{
typedef struct{
char num[8];
char name[8];
int score;
} ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
} LNode,*LinkList;
/** A single chain table with leading nodes
* initialization
*/
int InitList_L(LinkList &L){
L=new LNode;// or L=(LinkList) malloc(sizeof(LNode));
L->next=NULL;
return OK;
}
/** Judge whether the list is empty
* Empty return 1
* Otherwise return to 0
* */
int ListEmpty(LinkList L){
if (L->next)
return 0;
else
return 1;
}
/** Destruction of Single Chain Watch
* Release all nodes in sequence starting from the pointer
* */
int DestroyList_L(LinkList &L){
LinkList p;
while (L!=NULL){
p=L;
L=L->next;
delete p;// free(p);
}
return OK;
}
/** Empty single chain table
* Release all nodes in turn starting from the initial node
* */
int ClearList_L(LinkList &L){
LNode *p;
while (L->next!=NULL) {
p = L->next;
L->next = p->next;
delete p; //free(p);
}
return OK;
}
/** Single chain list L The long table
* */
int LengthList_L(LinkList L,int &i){
i=0;
LNode *p;
p=L->next;
while (p){
i++;
p=p->next;
}
return OK;
}
/** Take the... Of the single linked list i Element values
* */
int GetILNode(LinkList L,int i,ElemType &e){
LNode *p;
if (i<1)return ERROR;
p=L->next;i--;
while (p!=NULL&&i-->0){
p=p->next;
}
if (i==0&&p!=NULL){
e=p->data;
return OK;
} else{
return ERROR;
}
}
/** Take the... Of the single linked list i Element values
* */
int GetILNode2(LinkList L,int i,ElemType &e){
LNode *p=L->next;
int j=1;
while (p&&j++<i){
p=p->next;
}
if (!p||i!=j) return ERROR;
e=p->data;
return OK;
}
/** According to the value lookup
* 1. The position of ( Physical address )
* 1. Sequence
* */
LNode *LocateElem_L(LinkList &L,ElemType e){
LNode *p;
p=L->next;
while (p&&p->data.name!=e.name){
p=p->next;
}
return p;
}
/** According to the value lookup
* 1. The position of ( Physical address )
* 1. Sequence
* */
int LocateElem1_L(LinkList &L,ElemType e){
LNode *p;
p=L->next;
int i=1;
while (p&&p->data.name!=e.name){
p=p->next;
i++;
}
if (p) return i;
return 0;
}
/** The insert
* */
int InsertList_L(LinkList &L,int i,ElemType e){
LNode *p=L;
int j=0;
while (p&&j<i-1){ // Find No i-1 Elements
p=p->next;
j++;
}
if (!p||i<1)return ERROR;
LNode *s = new LNode;
s->data=e;
s->next=p->next;
p->next=s;
return OK;
}
/** Delete operation
* */
int DeleteList_L(LinkList &L,int i,LNode *&e){
int j=0;
LNode *p=L;
while (p->next&&j<i-1){ // Find No i-1 Nodes p
p=p->next;
}
if (!p->next||i<1) return ERROR;
e=p->next;
p->next=e->next;
return OK;
}
/** establish - The first interpolation * */
int CreateList_H(LinkList &L,int n){
L=new LNode ;
L->next=NULL;
for (int i = n; i >0 ; --i) {
LNode *p=new LNode ;
// cin>>p->data;
p->next=L->next;
L->next=p;
}
}
/** establish - The tail interpolation
* */
int CreateList_E(LinkList &L,int n){
L=new LNode;
L->next=NULL;
LNode *r=L;
for (int i = n; i > 0; --i) {
LNode *p=new LNode;
// p->data=value
p->next=NULL;
r->next=p;
r=p;
}
}
};边栏推荐
- qt creater搭建osgearth环境(osgQT MSVC2017)
- Pat class B 1023 minimum decimals
- Day_08 传智健康项目-移动端开发-体检预约
- Repeated DNA sequences for leetcode topic resolution
- Layer 2技术方案进展情况
- 【Leetcode】431. Encode n-ary tree to binary tree (difficult)
- Day_ 12 smart health project jasperreports
- Radar canvas
- Difference between MySQL read committed and repeatability
- Causes and methods of exe flash back
猜你喜欢
![[cocos2d-x] custom ring menu](/img/fd/c18c39ae738f6c1d2b76b6c54dc654.png)
[cocos2d-x] custom ring menu

mongodb 4.x绑定多个ip启动报错

Day_ 10 smart health project - permission control, graphic report

Day_ 02 smart communication health project - appointment management - inspection item management

Machine learning 3-ridge regression, Lasso, variable selection technique

Day_11 传智健康项目-图形报表、POI报表

100-300 cases of single chip microcomputer program (detailed explanation of notes)

Progress of layer 2 technical scheme

【Cocos2d-x】截图分享功能

Cloud native database is the future
随机推荐
Repeated DNA sequences for leetcode topic resolution
CPU的功能和基本结构
(1) Basic learning - Common shortcut commands of vim editor
WordPress Core 5.8.2 - 'WP_ Query'SQL injection
Day_ 05 smart communication health project - appointment management - appointment settings
Design scheme of Small PLC based on t5l1
Day_07 传智健康项目-Freemarker
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch
Possible pits in mongodb project
exe闪退的原因查找方法
Day_08 传智健康项目-移动端开发-体检预约
Day_ 03 smart communication health project - appointment management - inspection team management
qt creater搭建osgearth环境(osgQT MSVC2017)
Day_06 传智健康项目-移动端开发-体检预约
Day_ 10 smart health project - permission control, graphic report
论文笔记: 多标签学习 LSML
I heard you want to embed ppt on WordPress website?
[vivado] xilinxcedstore introduction
[database backup] complete the backup of MySQL database through scheduled tasks
【Cocos2d-x】自定义环形菜单