#include<stdio.h> #include<stdlib.h> #define maxsize 100 typedef struct { int data[maxsize]; int len; }sqlist; void initlist(sqlist *L) { L->len=0; } void init(int a[],int n,sqlist *L) { for(int i=0;i<n;i++) L->data[i]=a[i]; L->len =n; } void printlist(sqlist *L) { for(int i=0;ilen ;i++) printf("%d ",L->data[i]); printf("\n"); } int main() { sqlist *L; //定义指向顺序表的指针 int a[10]; L=(sqlist *)malloc(sizeof(sqlist)); initlist(L); //构造一个空的顺序表 for(int i=0;i<10;i++) scanf("%d",&a[i]); init(a,10,L); printlist(L); system("pause"); return 0; }

C语言顺序表代码优化:初始化、赋值和打印

原文地址: https://www.cveoy.top/t/topic/pltb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录