版权声明:转载请注明原文地址即可,要是本文对您有些许帮助的话,请您在下方点个赞,谢谢啦ヾ(o◕∀◕)ノヾ https://blog.csdn.net/qq_33583069/article/details/88753232
#include<bits/stdc++.h>
using namespace std;
typedef struct{
int id;
#define MAXSIZE 20
char name[MAXSIZE];
double score;
}Node;
typedef struct{
Node* data;
int length,size;
}Linklist;
void initialize(Linklist* L,int size){
L->size=size;
L->length=0;
L->data=(Node*)malloc(size*sizeof(Node));
}
void insertNode(Linklist* L,int pos,Node obj){
assert(pos>=0&&pos<=L->length+1&&L->length+1<=L->size);
L->length++;
for(int i=L->length-1;i>=pos;i--)L->data[i]=L->data[i-1];
L->data[pos-1]=obj;
}
void displayLink(Linklist* L){
for(int i=0;i<L->length;i++)
cout<<"ID:"<<L->data[i].id<<"\tNAME:"<<L->data[i].name<<"\tScore:"<<L->data[i].score<<endl;
}
void removeNode(Linklist* L,int pos){
for(int i=pos-1;i<L->length;i++)L->data[i]=L->data[i+1];
L->length--;
}
int main(){
Linklist*L=new Linklist;; int t = 10;
// cout<<"The Size Of the Linklist:"; cin>>t;
initialize(L,t);
#define TESTING
#ifdef TESTING
insertNode(L,1,(Node){1,"hello",99.9});
insertNode(L,2,(Node){2,"world",100.0});
insertNode(L,3,(Node){3,"2333",98.0});
displayLink(L);
removeNode(L,2);
displayLink(L);
#endif
return 0;
}