㈠ 數據結構c語言版 編程
下面的這個程序不是很完整的,因為集合c沒有刪除ab中相同的數,還有下面的這個程序你要建在文件里才沒有錯誤,建源文件時,要表明是.c文件,在運行時,你要注意輸入的方式,如果你有問題再問好了
#include<stdio.h>
#include<stdlib.h>
#define
MAX
256
//typedef
int
List[MAX];
typedef
int
ElemType;
typedef
int
Status;
#define
OVERFLOW
-1
#define
OK
1
#define
LIST_INIT_SIZE
80
#define
LISTINCREMENT
10
typedef
struct
{
ElemType
*elem;
int
length;
int
listsize;
}
SqList;
typedef
SqList
List;
Status
InitList_Sq(
SqList*
L
)
{
(*L).elem
=
(ElemType*)
malloc
(LIST_INIT_SIZE*sizeof
(ElemType));
if
(!(*L).elem)
exit
(OVERFLOW);
(*L).length
=
0;
(*L).listsize
=
LIST_INIT_SIZE;
return
OK;
}
void
main()
{
int
ListLength(List
Lx);
void
GetElem(List
Lx,int
i,ElemType
*xi);
Status
InitList_Sq(
SqList*
L
);
void
ListInsert(List
*Lc,int
k,ElemType
e);
void
MergeList(List
La,List
Lb);
void
printElem(List
Lx);
List
La,Lb;
int
i;
InitList_Sq(&La
);
InitList_Sq(&Lb
);
printf("pls
input
length
of
La
,Lb\n");
scanf("%d,%d",&La.length,&Lb.length);
printf("intiating
La....\n");
for(i=1;i<=La.length;i++)
scanf("%d",&La.elem[i]);
printf("intiating
Lb....\n");
for(i=1;i<=Lb.length;i++)
scanf("%d",&Lb.elem[i]);
printf("values
of
La
are:\n");
printElem(La);
printf("values
of
Lb
are:\n");
printElem(Lb);
printf("starting
union...\n");
MergeList(La,Lb);
}
void
MergeList(List
La,List
Lb)
{
List
Lc;
int
i,j,k;
ElemType
ai,bj;
int
La_len=0,Lb_len=0;
i=j=1;k=0;
InitList_Sq(&Lc
);
La_len=ListLength(La);Lb_len=ListLength(Lb);
while((i<=La_len)&&(j<=Lb_len))
{
GetElem(La,i,&ai);
GetElem(Lb,j,&bj);
if(ai<=bj)
{ListInsert(&Lc,++k,ai);++i;}
else
{ListInsert(&Lc,++k,bj);++j;}
}
while(i<=La_len)
{
GetElem(La,i++,&ai);ListInsert(&Lc,++k,ai);
}
while(j<=Lb_len)
{
GetElem(Lb,j++,&bj);ListInsert(&Lc,++k,bj);
}
Lc.length=k;
printf("values
of
Lc
after
union:\n");
printElem(Lc);
}
void
printElem(List
Lx)
{
int
i;
for(i=1;i<=Lx.length;i++)
{
printf("%5d",Lx.elem[i]);
if(0==i%5)
printf("\n");
}
printf("\n");
}
void
GetElem(List
Lx,int
i,ElemType
*xi)
{
if(i>0
&&
i<=Lx.length)
*xi=Lx.elem[i];
//
printf("current
value
get:
%d\n",Lx[i]);
//
printf("current
value
get:
%d\n",xi[i]);
}
int
ListLength(List
Lx)
{
return
Lx.length;//
}
void
ListInsert(List
*Lc,int
k,ElemType
e)
{
(*Lc).elem[k]=e;
//printf("insert
success
to
e=%d\n",e);
}
㈡ c語言常見的數據結構有哪些
1、線性數據結構
元素之間一般存在元素之間存在一對一關系,是最常用的一類數據結構,典型的有:數組、棧、隊列和線性表。
2、樹形結構
結點間具有層次關系,每一層的一個結點能且只能和上一層的一個結點相關,但同時可以和下一層的多個結點相關,稱為“一對多”關系,常見類型有:樹、堆。
3、圖形結構
在圖形結構中,允許多個結點之間相關,稱為“多對多”關系。
(1)線性數據結構:元素之間一般存在元素之間存在一對一關系,是最常用的一類數據結構,典型的有:數組、棧、隊列和線性表
(2)樹形結構:結點間具有層次關系,每一層的一個結點能且只能和上一層的一個結點相關,但同時可以和下一層的多個結點相關,稱為“一對多”關系,常見類型有:樹、堆
(3)圖形結構:在圖形結構中,允許多個結點之間相關,稱為“多對多”關系
㈢ 數據結構C語言編程
#include"stdio.h"
#include<stdlib.h>
#include"time.h"
intmain(intargv,char*argc[]){
doublex[10]={0.0,};
inti;
srand((unsigned)time(NULL));
while(rand()%10000!=0){//
for(i=0;i<9;x[i++]=x[i+1]);
x[9]=rand()/32767.0*100000;//模擬採集數據
}
for(i=0;i<10;printf("%10.3f ",x[i++]));//輸出最後10個數
return0;
}
運行樣例:
㈣ C語言數據結構編程
#include<stdio.h>
#include<stdlib.h>
#include"string.h"
intmain(intargc,char*argv[])
{
char*buffer=(char*)malloc(sizeof(char)*100);
char*b=(char*)malloc(sizeof(char)*100);
memset(buffer,'