-
Notifications
You must be signed in to change notification settings - Fork 0
/
myseqlist.c
54 lines (52 loc) · 863 Bytes
/
myseqlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 200
typedef int ElemType;
typedef struct seqlist
{
ElemType *data;
int listlength;
int listsize;
}seqlist;
void initlist( seqlist *L )
{
L->data = ( ElemType* )malloc( MAXSIZE*sizeof(ElemType) );
L->listlength = 0;
L->listsize = MAXSIZE;
}
void insertelem(seqlist *L, int pos, ElemType e )
{
int j = 0;
for( j = L->listlength+1; j>pos; j--)
{
L->data[j] = L->data[j-1];
}
L->data[pos-1] = e;
L->listlength++;
}
void printlist(seqlist *L)
{
int i = 0;
for( i = 0; i<L->listlength; i++)
{
printf("%d ", L->data[i]);
}
}
int main()
{
seqlist L;
int i = 0;
int n = 0;
int len = 0;
initlist(&L);
printf("Please input length >: ");
scanf("%d", &len);
printf("Please input elem >:");
for( i = 1; i<len+1; i++)
{
scanf("%d",&n);
insertelem(&L,i,n);
}
printlist(&L);
return 0;
}