編寫函式findlist(l,x)查詢順序表中的值為x的資料並返回索引,如果沒找到則返回-1
#include "stdafx.h"
#include "seqlist.h"
int main()
int value;//要查詢的資料
printf("\n輸入要查詢的資料:\n");
scanf("%d", &value);
int index = listfind(mylist, value);//資料索引
if(index != -1)//如果有這個資料,列印資料索引
printf("值為 %d 的索引為 %d ", value, index);
return0;}
/*輸出:
1 2 3 4 5 6 7 8 9 10
輸入要查詢的資料:
5值為 5 的索引為 4
*/
seqlist.h原始碼:
#pragma once
#include "stdio.h"
#define maxsize 100
typedef
int datatype;
typedef
struct seqlist;
void listinitiate(seqlist *l)
int listlength(seqlist l)
int listinerst(seqlist *l, int i, datatype x)
else
if (i<0 || i>l->size)
else
}int listdelete(seqlist *l, int i, datatype *x)
else
if (i<0 || i>l->size - 1)
else
}int listget(seqlist l, int i, datatype *x)
else
}int listfind(seqlist l, datatype x)
}if (!hasfind)
}
資料結構順序表的查詢 資料結構 2 1順序表
線性結構是資料結構中最基礎 最簡單的一種資料結構型別,其中最典型的就是線性表 具有 相同特性 的資料元素的 有限序列 相同特性 所有元素屬於同一資料型別 有限資料元素個數是有限的 序列資料元素由邏輯序號唯一確定 用邏輯序號來確定的特性使得線性表中可以有多個相同值的元素 線性表中所含元素的個數叫做線性...
資料結構 實驗1 順序表
問題描述 設計乙個順序表操作演示程式。基本要求 順序表操作演示程式提供乙個使用者介面,可演示的基本功能包括 1 初始化順序表 2 輸入並建立順序表 3 輸出順序表中的元素 4 在順序表指定位置插入元素 5 在順序表指定元素之前插入元素 6 刪除順序表指定位置的元素 7 刪除順序表指定元素之前的元素 ...
資料結構實驗1 順序表
1 include 2 include 3 include 4 include 5 include 6 include 7 include 8 include 9 include 10 include 11 using namespace std 1213 define ok 1 14 define...