当前位置:生活全书馆 >

综合知识

> 线性表怎么写

线性表怎么写

1. 线性表怎么写

A是一个结构数组,A[i].data是值,A[i].next是下标,表示下一个数据元素的位置。A[0]是线性表的表头。当A[i].next==0时,表示A[i].data是线性表的最后一个数据元素。

线性表怎么写

通过A[0].next可以找出线性表的第一个元素的下标为3,第一个数据元素为A[3].data,即78,根据A[3].next也就是2,找到第二个数据元素A[2].data,即50,再根据A[2].next找到第三个元素。以此类推。

这道题的答案是:78,50,40,60,34,90

2. 数据结构中关于顺序结构中的线性表的建立怎么写

typedef struct{

int *elem;

int len;

int listsize;

}sqlist;

sqlist creat(){ //这只是建立的方法,主函数自己写吧

sqlist L;

int n;

printf("请输入线性表元素的个数:n");

scanf("%d",&n);

L.elem=(int*)malloc(ls*sizeof(int));

L.len=n;

L.listsize=ls;

return L;}

3. 如何把这些数据用线性表表示出来

struct table tab[N]

{

char tab[0].Dest=203.74.205.0

char tab[0].Mask=255.255.255.0

char tab[0].Gate=203.74.205.1

char tab[0].Inte=203.74.205.1

char tab[1].Dest=203.74.206.0

char tab[1].Mask=255.255.255.0

char tab[1].Gate=203.74.206.1

char tab[1].Inte=203.74.206.1

char tab[2].Dest=203.74.207.0

char tab[2].Mask=255.255.255.0

char tab[2].Gate=203.74.207.1

char tab[2].Inte=203.74.207.1

char tab[3].Dest=203.74.208.0

char tab[3].Mask=255.255.255.0

char tab[3].Gate=203.74.206.2

char tab[3].Inte=203.74.206.1

};

4. C语言中怎么定义个线性表

1、定义结构体类型,这里需要利用指针和结构体,其中m和n分别表示矩阵的行和列。

2、为矩阵申请储存空间,注意这里使用了malloc()函数。

3、初始化矩阵,这里将矩阵初始化为m*n的数组,且矩阵中的每一个元素的值均为0。

4、释放存储空间。

5、一般在定义阶段就确定数组的大小,输入数字即为数组大小。

6、然后,可以对数组进行初始化,在花括号{}中输入就完成了。

5. 线性表的主函数要怎么写

/*请输入待建立的表长 : 5请输入5个元素用空格分开 : 56 54 34 12 76成功建立表!插入元素10。

56 10 54 34 12 76删除第3个元素。56 10 34 12 76Press any key to continue*/#include using namespace std;#define MaxSize 100typedef int datatype;typedef struct { datatype data[MaxSize]; int last;}SeqList;void Init_SeqList(SeqList*L) { int i; cout > L->last; cout last last;i++) { cin >> L->data[i]; } cout last == MaxSize - 1) { cout L->last + 2)) { cout last;j >= i - 1;j--) L->data[j + 1] = L->data[j]; L->data[i - 1] = x; L->last++; return 1;}int Delete_SeqList(SeqList *L,int i) { int j; if((i L->last + 1)) { cout last;j++) L->data[j - 1] = L->data[j]; L->last--; return 1;}int Locate_SeqList(SeqList *L,datatype x) { int i = 0; while((i last) && (L->data[i] != x)) i++; if(i >= L->last) return -1; else return 0;}void Display_SeqList(SeqList *L) { if(L == NULL) cout last;i++) printf("%d ",L->data[i]); cout 追问: 运行不了啊。

追答: 代码上边的/* 。

. */中的内容是在VC下的运行结果,应该可以的。

评论0 0 0。

6. 数据结构线性表void Creat

看到void Creat_Sq(SqList* L),我想问下InitList_Sq()函数的参数是否也是SqList* L类型的,由于你函数void Creat_Sq(SqList* L)参数是指针类型传入的所以。你在主函数中定义SqList l,就不对了,应该为SqList *l=(SqList *)malloc(sizeof(SqList));同时你的ElemType类型中的数据类型是什么样的,还有创建链表函数插入节点在头部还是尾部等,你要说清楚才能帮你

下面是我写的一个例子程序,基本根据你的要求来的,只是一种用户插入方式,很简单,仅供参考:

#include <iostream> using namespace std; #define ElemType int #define OK 1

const int LIST_INIT_SIZE=100; const int LISTINCREMENT=10;

typedef struct { ElemType * elem; int length; int listsize; int incrementsize; }SqList;

int InitList_Sq (SqList &L, int maxsize= LIST_INIT_SIZE, int incremesize= LISTINCREMENT) { L.elem = new ElemType [maxsize]; if(&L==NULL) return 0; L.length = 0; L.listsize = maxsize; L.incrementsize = incremesize; return OK; }

void Creat_Sq(SqList &L) { int i; char choose; for(i=L.length;i<L.listsize;) { cout<<"Please input the number: "; cin>>L.elem[i]; cout<<"continue to input?[n/y]"; cin>>choose; L.length++; i=L.length; if(choose=='n'||choose=='N') break; } }

void Free_Sq(SqList &L) { delete L.elem; }

void Print_Sq(SqList &L) { int i; for(i=0;i<L.length;i++) { cout<<L.elem[i]<<' '; } cout<<endl; }

int main() { SqList l; InitList_Sq(l); Creat_Sq(l); Print_Sq(l); Free_Sq(l); return 0; }

运行结果如下:

不好意思前面误导了你一下,本来以为你是C语言我想C语言没有引用类型的。线性表创建不是什么问题,难度在插入和删除要进行数据移动的,如果还有什么问题可以追问。

7. 写出线性表操作的算法

#include<stdio.h>

void search(int a[];int b)

{

int i=0;

while(i<10&&a[i]!=b)

i++;

if(i<10){

printf("found!");

return;

}

else

{

printf("not found");

return;

}

}

main()

{

int a[]={12,26,39,30,52,43,80,92,101,89};

search(a,b);

}

标签: 线性表
  • 文章版权属于文章作者所有,转载请注明 https://shqsg.com/zh-my/zonghezhishi/oweql2.html