当前位置:网站首页>Initial knowledge of data linked list
Initial knowledge of data linked list
2022-04-22 06:01:00 【assassin$】
Simple implementation of data linked list
notes :
- Compile environment vs2019;
- For beginners , Big guys don't have to waste their time reading ;
- If you have any questions, please leave a message or private letter to discuss ;
First of all, we need to know the basic structure of the data linked list
- Three basic quantities are written in my linked list : Capacity , Current capacity , The pointer
- The following functions are realized : Additions and deletions
- Understand a knowledge point : The pointer can be changed into a variable through dynamic memory application
structured :

function.p Code snippet in
enum TwoInformation {
ERROR = -1, OK = 1 };
// Define enumeration types , Convenient error finding
typedef struct myList
{
int Capacity;
int cur_Size;
int* p_MyArr;
}MYLIST, * p_MyList;
p_MyList createList(int);
int AddLData(p_MyList& p, int data);
int delData(p_MyList& p, int);
void show(p_MyList& p);
int Empty(p_MyList& p);
int getSize(p_MyList& p);
int lookup(p_MyList& p,int );
int modify(p_MyList& p, int, int);
function.cpp In the code ( The concrete realization of function ):
#include<iostream>
#include<assert.h>
#include"function.h"
using namespace std;
p_MyList createList(int max_Size)
{
p_MyList plist = (p_MyList)malloc(sizeof(MYLIST));
assert(plist);
// About assert The function is probably used to see whether the memory application is successful , Search by yourself
plist->cur_Size = 0;
plist->Capacity = max_Size;
plist->p_MyArr = (int*)malloc(sizeof(int) * max_Size);
assert(plist->p_MyArr);
return plist;
}
int AddLData(p_MyList& p, int data)
{
if (p->cur_Size >= p->Capacity)
{
cout << "List is full!" << endl;
return ERROR;
}
p->p_MyArr[p->cur_Size++] = data;
return OK;
}
int delData(p_MyList& p, int position)
{
if (p->cur_Size <= 0)
{
cout << "List is Empty!" << endl;
return ERROR;
}
if (p->cur_Size == (position - 1))
p->cur_Size--;
else
{
for (int i = (position - 1); i < p->cur_Size; i++)
{
p->p_MyArr[i] = p->p_MyArr[i + 1];
}
}
p->cur_Size--;
return OK;
}
void show(p_MyList& p)
{
for (int i = 0; i < p->cur_Size; i++)
cout << p->p_MyArr[i] << ' ';
}
int Empty(p_MyList& p)
{
if (p->Capacity == NULL)
return ERROR;
return p->Capacity == 0;
}
int getSize(p_MyList& p)
{
return p->cur_Size;
}
int lookup(p_MyList& p, int data)
{
if (p->cur_Size <= 0)
{
cout << "List is Empty!" << endl;
return ERROR;
}
for (int i = 0; i < p->cur_Size; i++)
{
if (p->p_MyArr[i] == data)
{
cout << endl;
cout << "Query to number " << data << endl;
return OK;
}
}
cout << endl;
cout << "no seek to number" << endl;
return OK;
}
int modify(p_MyList& p, int position, int data)
{
if (p->cur_Size <= 0)
{
cout << "List is Empty!";
return ERROR;
}
for (int i = 0; i < p->cur_Size; i++)
{
if (i == position - 1)
{
p->p_MyArr[i] = data;
}
}
return OK;
}
main.cpp Call in :
#include<iostream>
#include"class.hpp"
#include"function.h"
using namespace std;
void test01()
{
p_MyList p = createList(10);
for (int i = 0; i < 10; i++)
{
AddLData(p, i);
}
show(p);
delData(p,10);
cout << endl;
show(p);
lookup(p, 8);
modify(p, 2, 9);
show(p);
}
int main(int argv, char* argc)
{
test01();
char ch=getchar();
return 0;
}
Finally, a running screenshot is attached :

The first line inserts the element ;
The second line deletes the element ;
The third line queries whether there is the element ;
The fourth line modifies the element ;
版权声明
本文为[assassin$]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220541000834.html
边栏推荐
- Standard input, standard output, standard error redirection and pipeline
- 抓包工具mitmproxy和Anyproxy
- Pytorch environment preparation
- QT学习之安装QT
- Torch uses stepping on the pit diary and matrix to speed up the operation
- What compiler is used for beginners of C language (there is a surprise at the end of the article)
- Golang learning and school recruitment experience
- STM32学习笔记2——设置GPIO寄存器实现流水灯
- WGS84 coordinate conversion, map picking, WGS84 coordinate tool recommended
- Blue Bridge Cup 31 day sprint Day17
猜你喜欢

第84篇 LeetCode剑指Offer动态规划(一)斐波那契数列

Blue Bridge Cup 31 day sprint Day3

PCA in scikit learn

Alist easy to use guide

苹果cms设置本地播放器 ckplayer(版本:ckplayerx)

Golang calculates the number of days rounded to time

第85篇 LeetCode剑指Offer动态规划(二)青蛙跳台阶问题

Blue Bridge Cup Sprint - DFS

11 - process control - for loop

ubuntu20.0.4下在终端安装数据库
随机推荐
RTL8367学习笔记3——ACL访问控制列表
Meilisearch usage record
链表的逆序输出 C语言三行代码 递归栈
STM32学习笔记4——HC_SR04超声波测距模块的调试记录
STM32学习笔记3——GPIO的输入引脚
05-变量及标识符
The postgraduate entrance examination is over
ShardingException: Cannot find data source in sharding rule, invalid actual data node is
RTL8367学习笔记1——基础知识
Blue Bridge Cup 31 day sprint Day8
初识数据链表
08 - 程序的输入和输出
RTL8367学习笔记2——网络配置操作扫盲
Pytorch deep learning practice_ 10 basis of convolutional neural network CNN
c语言开发postgres自定义函数
14 - container - tuple
12 - container - string
ifix问题汇总Q&A(个人记录)
05 - variables and identifiers
meilisearch使用记录