當前位置:首頁 » 編程語言 » c語言數據結構編程
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言數據結構編程

發布時間: 2022-12-15 12:48:50

㈠ 數據結構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,'',100);
memset(b,'',100);
chars1[10]={""};
chars2[10]={""};
chars3[10]={""};
inti1,i2,i3,i,j=0;
intlen=strlen(gets(buffer));
for(i=0;i<len;i++)
{
if(buffer[i]!='')
{
b[j]=buffer[i];
j++;
}
}
len=strlen(b);
i1=0;i2=0;i3=0;
for(i=0;i<len/3;i++)
{
switch(b[i*3])
{
case'1':
s1[i1++]=b[i*3];
s1[i1++]=b[i*3+1];
s1[i1++]=b[i*3+2];

break;
case'2':
s2[i2++]=b[i*3];
s2[i2++]=b[i*3+1];
s2[i2++]=b[i*3+2];

break;
case'3':
s3[i3++]=b[i*3];
s3[i3++]=b[i*3+1];
s3[i3++]=b[i*3+2];

break;
}
}
printf(" ");
intn=strlen(s3);
for(i=n-3;i>=0;i-=3)
{
printf("%c%c%c",s3[i],s3[i+1],s3[i+2]);
}
n=strlen(s2);
for(i=n-3;i>=0;i-=3)
{
printf("%c%c%c",s2[i],s2[i+1],s2[i+2]);
}
n=strlen(s1);
for(i=n-3;i>=0;i-=3)
{
printf("%c%c%c",s1[i],s1[i+1],s1[i+2]);
}
return0;
}

㈤ 數據結構 c語言編程

你的 crt_linklist函數有問題,應為在你的主函數中,你在調用 crt_linklist函數時,實際上進行的的是值傳遞!你後來的初始化函數init_linklist以及創建鏈表函數crt_linklist對p都沒有什麼影響!這兩個函數所做的工作就只是對自己的形參處理了而已,當函數調用結束時,一切又消失了,實參p還是原來的樣子。你可以考慮在主函數中這樣修改就可以了:

int main()
{
lnode l;
elemtype i=30;
crt_linklist(&l,i);
output_linklist(&l);
return 0;
}

這種問題自己必須想明白,我們當初學習時也經常碰到這種問題,但只要你好好想想,這些問題就都能想明白的,你可以不斷實踐加深自己的理解!

㈥ 數據結構C語言程序設計編程題,請問這個程序怎麼編

#include<stdio.h>
#include<stdlib.h>
typedef struct List
{
int data;
struct List *next;
}list;

int main()
{
list *L = (list*)calloc(1, sizeof(list)); //頭結點
L->next = NULL;
int n, k, i;
scanf("%d%d", &n, &k);

list *s, *q = L;
for (i=0; i<n; ++i) //賦初值
{
s = (list*)calloc(1, sizeof(list));
s->data = i+1;
s->next = NULL;
q->next = s;
q = s;
}

q->next = L->next; //讓尾結點指向頭結點的下一個,即第一個人的位置,單向循環鏈表創建完成
q = L->next; //讓q指向頭結點的下一個

while (q->next != q) //只剩一個元素時,退出循環
{
for (i=1; i<k-1; ++i)
{q = q->next;} //q指向刪除節點的前一個
s = q->next; //s指向刪除節點
q->next = s->next; //將去除s後的鏈表重新連接起來
q = q->next; //讓q指向下次循環的起始位置
//printf("%d ", s->data);
free(s);
s = NULL;
}

printf ("%d\n", q->data);
free(q);
q = NULL;
free(L);
L = NULL;
return 0;
}

㈦ C語言實現常用數據結構(一)

實現了鏈表,棧、哈希表等
哈希表由數組加鏈表實現。通過計算key的哈希值,將哈希值轉成int類型並與數組長度進行與運算得到數組下標,數組每個元素都是一個鏈表,默認為NULL。
通過InitHashTable函數得到初始化的哈希表。已實現功能有:添加鍵值、刪除鍵值、根據鍵獲取值,清理所有鍵值對、回收哈希表,可以根據例子遍歷鍵值。
Key可以擴展為任何類型,但需要實現相應類型HashCode的演算法,此處只支持字元串類型。

C語言實現常用數據結構二
項目地址

md5.h

md5.c

m_hashtable.h

m_hashtable.c

測試使用

㈧ C語言編程(數據結構)

int*getnum(inta)
{
staticintn[10];
inti=a;
for(i=1;i<=a;i++)
{
intk=i;
while(i>0)
{
n[i%10]++;
i/=10;
}
i=k;
}
returnn;
}
intmain()
{
int*m=getnum(11);
inti;
for(i=0;i<10;i++)
{
printf("%d",m[i]);
}
getch();
return0;
}