#include <stdio.h> #include <the iostream> #include < the malloc .h> #define Max 10 the using namespace STD; typedef struct { char Data [Max]; int length; } sqlist; void initlist (sqlist * & L) / / linear table initialization * & representatives can address changes l { l = (sqlist *) the malloc ( the sizeof (sqlist)); l -> length = 0 ; } void easyinsert (sqlist * l) { char C =getchar(); if(l->length>Max) { return ; } l->data[l->length++]=c; } void display(sqlist l) { for(int i=0;i<l.length;i++) { cout<<l.data[i]; } cout<<endl; } int leng(sqlist l) { cout<<l.length<<endl; return l.length; } void getelem(sqlist l,int n) { if(n<1||n>l.length) { return ; } char e; e=l.data[n-1]; cout<<e<<endl; } void weizhi(sqlist l,char c) { for(int i=0;i<l.length;i++) { if(c==l.data[i]) { cout<<i+1<<"\n"; } } } void charu(sqlist *l,char c,int n) { if(n<1||n>l->length) { return ; } l->length++; int i; for(i=l->length;i>n;i--) { l->data[i-1]=l->data[i-2]; } l->data[i-1]=c; } void shanchu(sqlist *l,int i) { if(i<1||i>l->length) { return ; } l->length--; for(int j=i-1;j<l->length;j++) { l->data[j]=l->data[j+1]; } } int main() { sqlist *l; initlist(l); easyinsert(l); easyinsert(l); easyinsert(l); easyinsert(l); easyinsert(l); display(*l); leng(*l); getelem(*l,. 4); Weizhi ( * L, ' C ' ); Charu (L, ' G ' , . 5 ); the display ( * L); shanchu (L, . 3 ); the display ( * L); }
It must be initialized with * & l, if there are changes to the rest of the table is called a linear pointer
The reason: https://www.cnblogs.com/xiang-little/p/5840809.html
void initlist (sqlist * & l) // initialize * & Representative linear form can be changed to address l
{
l = (sqlist *) the malloc (the sizeof (sqlist));
L-> length = 0 ;
}