導航:首頁 > 編程語言 > c數據結構編程題

c數據結構編程題

發布時間:2022-08-01 04:58:36

❶ C語言版數據結構編程

//試編寫一道在單鏈表中數據域值為a的結點之後,
//插入一個新結點的演算法.若原鏈表中無數據域值為a的結點,
//則把新結點插入到表尾.設新結點數據域值為x.小弟初學,謝謝大家啦

//定義結點
typedef struct node{
int data;
struct node *next;
}LNode ,*LinkList;

//list為單鏈表的表頭指針,插入元素為x
void insert(LinkList &list,int x)
{
LinkList p,q;

//生成一個結點其結點值為x
p=( LinkList)malloc(sizeof(LNode));
p->data=x;
p->next=NULL;
//查找結點值為a的結點,用r指向q的前一個結點
q=list;
while(q!=NULL&&q->data!=a)
{
r=q;
q=q->next;
}
//插入x
//存在數據域值為a的結點
if(q->data==a)
{
p->next=q->next;
q->next=p;
}
//不存在數據域值為a的結點
else{
q->next=p
}

}

❷ 數據結構(C語言版)編程題 急急急~

改一下這兩句
if(estimate(p)==0) printf("此字元串符合要求類型。");
else printf("此字元串不符合要求類型。");

if(estimate(p)) printf("此字元串符合要求類型。");
else printf("此字元串不符合要求類型。");

❸ c語言編程 數據結構題

C語言實現鏈式棧,進行兩個棧的進出棧操作,並分別輸出棧的內容,參考代碼如下:

#include<stdio.h>
#include<stdlib.h>
typedefstructLnode{
intdata;
structLnode*next;
}Lnode,*Linklist;
voidPrint(Linklistlist);
voidPush(Linklistlist,intdata);
intPop(Linklistlist,int*data);
voidDelete(Linklistlist);
intmain(void)
{
Linklists,t;
intdata;
s=(Lnode*)malloc(sizeof(Lnode));
t=(Lnode*)malloc(sizeof(Lnode));
if(s==NULL||t==NULL)
return1;
s->next=NULL;
t->next=NULL;
Push(s,1);
Push(s,2);
Push(s,3);
Push(s,4);
Push(s,5);
printf("鏈表s=");
Print(s);
printf("鏈表t=");
Print(t);
Pop(s,&data);
Push(t,data);
Pop(s,&data);
Push(t,data);
Pop(s,&data);
Push(t,data);
Pop(s,&data);
Push(t,data);
Pop(s,&data);
Push(t,data);
printf("鏈表s=");
Print(s);
printf("鏈表t=");
Print(t);
Delete(s);
Delete(t);
return0;
}
voidPush(Linklistlist,intdata)
{
Lnode*p=(Lnode*)malloc(sizeof(Lnode));
if(p==NULL)exit(1);
p->data=data;
p->next=list->next;
list->next=p;
}
intPop(Linklistlist,int*data)
{
Lnode*p=list->next;
if(p==NULL)return0;
list->next=p->next;
*data=p->data;
free(p);
return1;
}
voidPrint(Linklistlist)
{
Lnode*p;
for(p=list->next;p!=NULL;p=p->next)
printf("%d",p->data);
printf(" ");
}
voidDelete(Linklistlist)
{
Lnode*p=list->next,*q;
while(p!=NULL){
q=p;
p=p->next;
free(q);
}
list->next=NULL;
}

❹ 數據結構編程題 C語言!

2. 元素類型未定,比較方法未定,不能進行排序。

3. printf("%o",i);// C, 8進制
cout<<std::oct<<i; // C++, 8進制
輸入cin>>i

4. 用STL的list,鏈表不用自己謝啦。(C++ ONLY)
#include <list>
using namespace std;

5. 這個太多了不寫。

6. STL, list
list<int> int_lst;
list<int>::iterator i = int_lst.begin()
for(;i != int_lst.end(); ++i)

刪除節點:int_lst.erase(i)
PS:這里有陷阱,嘿嘿,注意啦。
交換節點:
int a = (*i);
(*i) = *(i+1);
*(i+1) = a;

完事啦。

❺ 請教一個C語言的數據結構編程的題目,高手進!

#include <stdio.h>

int A[6][6];
int i,j,sides=0,degree[6];
int main() {

for(i=0;i<6;i++) for(j=0;j<6;j++){
scanf("%d",&A[i][j]);

if(A[i][j]){
sides++;
degree[i]++;
degree[j]++;
}
}

sides/=2;
printf("total number of sides is %d \n",sides);
for(i=0;i<6;i++) {
degree[i]/=2;
printf("degree of vertex %d is %d \n",i,degree[i]);
}

return 0;
}

數據:
0 1 1 0 1 0
1 0 1 1 0 1
1 1 0 0 1 1
0 1 0 0 1 0
1 0 1 1 0 1
0 1 1 0 1 0

輸出:
total number of sides is 10
degree of vertex 0 is 3
degree of vertex 1 is 4
degree of vertex 2 is 4
degree of vertex 3 is 2
degree of vertex 4 is 4
degree of vertex 5 is 3

說明:
A[i][j]=0 代表 i節點與j節點無連接,因為是無向的, A[j][i]一定=0.
A[i][j]=1時亦然.

因此 A[i][j]圖一定是對稱的.

所以每個邊都計算了2次,度也是
因此最後整除2

❻ 數據結構(用C語言描述)編程題求助!!!

這是個二叉排序樹例題,希望對你有幫助! #include "stdio.h" # include "stdlib.h" struct Bnode {int data; struct Bnode *lchild,*rchild; }; void insertbst(Bnode *&t, Bnode *s) {if (t== NULL) t=s; else if (s->data< t->data) insertbst(t-> lchild,s); else insertbst(t-> rchild,s); } void inorder(Bnode *t) { if (t!=NULL) { inorder(t->lchild); printf("%d ", t->data); inorder(t->rchild); } } void main() {int i,x; Bnode *t=NULL,*s; for (i=1;i<=4;i++) {scanf("%d",&x); s=( Bnode *)malloc(sizeof(Bnode)); s->data=x; s-> lchild= NULL; s-> rchild= NULL; printf("\n"); insertbst(t,s); } inorder( t); printf("\n"); }

閱讀全文

與c數據結構編程題相關的資料

熱點內容
樹莓派都用python不用c 瀏覽:755
access文件夾樹的構造 瀏覽:660
安卓多指操作怎麼設置 瀏覽:656
linux樹形目錄 瀏覽:727
平方根的簡單演算法 瀏覽:898
千牛訂單頁面信息加密取消 瀏覽:558
單片機自製紅外遙控燈 瀏覽:719
伺服器最小配置怎麼弄 瀏覽:853
ibm伺服器硬體如何升級 瀏覽:923
全球程序員節點贊 瀏覽:986
php函數傳遞數組 瀏覽:631
人工峰群演算法的目標函數 瀏覽:468
如何刪加密文檔 瀏覽:105
塗鴉app一鍵執行如何刪除 瀏覽:756
安卓手機如何打開fr3文件 瀏覽:743
壓縮袋8絲和14絲是什麼意思 瀏覽:647
程序員大咖java 瀏覽:70
蘋果手機文檔安卓上怎麼打開 瀏覽:527
如何做淘寶代理伺服器 瀏覽:672
gz壓縮文件夾 瀏覽:179