C语言实现顺序线性表及request for member''in something not a structure or union
2017-03-08 16:47
513 查看
最近开始复习数据结构,就从线性表开始,哈哈哈!
C语言实现了顺序线性表的定义、获取元素、插入元素及删除元素的操作。
经DEV C++编译运行通过。
虽然不复杂,但是因为薄弱的C语言知识还是遇到了一些问题。
【Error】request for member 'length' in something not a structure or union
这个问题出现在ListInsert()和ListDelete()中,刚开始以为是函数里的L要换成*L,发现不对,然后发现为什么GetElem()函数里没有报这个错,网上查了一下,发现是:
结构体指针要使用->来引用结构体中的成员,插入和删除函数中传入的就是结构体指针。
C语言实现了顺序线性表的定义、获取元素、插入元素及删除元素的操作。
#include<stdio.h> #define MAXSIZE 20 typedef int ElemType; typedef struct { ElemType data[MAXSIZE]; int length; }SqList; #define OK 1 #define ERROR 0 typedef int Status; Status GetElem(SqList L,int i,ElemType *e) { if(L.length==0||i<1||i>L.length) return ERROR; *e=L.data[i-1]; return OK; } Status ListInsert(SqList *L,int i,ElemType e) { int k; if(L->length==MAXSIZE||i<1||i>L->length+1) return ERROR; if(i<=L->length) { for(k=L->length-1;k>=i-1;k--) L->data[k+1]=L->data[k]; } L->data[i-1]=e; L->length++; return OK; } Status ListDelete(SqList *L,int i,ElemType *e) { int k; if(L->length==0||i<1||i>L->length) return ERROR; *e=L->data[i-1]; if(i<L->length) { for(k=i;k<L->length;k++) L->data[k-1]=L->data[k]; } L->length--; return OK; } int main() { SqList sq; sq.data[0]=5; sq.data[1]=4; sq.data[2]=3; sq.data[3]=2; sq.data[4]=1; sq.length=5; int a=0; for(a=0;a<sq.length;a++) { printf("%d\n",sq.data[a]); } int sqd1; printf("%d\n",GetElem(sq,2,&sqd1)); printf("%d\n",sqd1); int sqd2=6; printf("%d\n",ListInsert(&sq,4,sqd2)); printf("%d\n",sq.data[3]); printf("%d\n",ListDelete(&sq,4,&sqd2)); printf("%d\n",sqd2); return 0; }
经DEV C++编译运行通过。
虽然不复杂,但是因为薄弱的C语言知识还是遇到了一些问题。
【Error】request for member 'length' in something not a structure or union
这个问题出现在ListInsert()和ListDelete()中,刚开始以为是函数里的L要换成*L,发现不对,然后发现为什么GetElem()函数里没有报这个错,网上查了一下,发现是:
结构体指针要使用->来引用结构体中的成员,插入和删除函数中传入的就是结构体指针。
相关文章推荐
- Jni使用过程中出现 error: request for member 'FindClass' in something not a structure or union,解决办法
- JNI遇到error: request for member 'FindClass' in something not a structure or union
- C 语言编译时报错 request for member''in something not a structure or union
- error: request for member ‘on_url’ in something not a structure or union
- request for member 'flags' in something not a structure or union
- JNI遇到error: request for member 'FindClass' in something not a structure or union
- C语言程序编译错误 request for member 'num' in something not a structure or union
- JNI_OnLoad编译错误:request for member 'GetEnv' in something not a structure or union
- JNI遇到error: request for member 'FindClass' in something not a structure or union
- error: request for member 'FindClass' in something not a structure or union
- JNI遇到error: request for member 'FindClass' in something not a structure or union
- JNI_OnLoad编译错误:request for member 'GetEnv' in something not a structure or union
- error: request for member 'nameLabel' in something not a structure or union 的原因
- JNI遇到error: request for member 'FindClass' in something not a structure or union
- android JNI之 'GetObjectClass' in something not a structure or union
- 编译报request for member '***' in something not a structure or union的原因,以及解决方法
- 顺序线性表——通过存放地址,实现顺序存储--C语言简单实现
- c语言实现顺序结构的线性表,可自动增加长度的
- 用C语言定义Bool类型(包括数据表示和操作实现),至 少包含and(与)、or(或)、not(非)、equiv(相等)这4个操作。
- The server cannot or will not process the request due to something that is perceived to be a client