當前位置:首頁 » 編程語言 » 百行C語言

百行C語言

發布時間: 2022-04-23 14:58:24

❶ 如何用c語言做游戲開發

你錯了~ 理論上說,其他語言做到的c語言一定能夠做到~而且效率高得多,只不過其他語言一句話就能做到的,C語言可能要上百行代碼~ c語言時代,一個大軟體 動輒幾十萬行,幾百萬行代碼,其中出一個錯誤,是絕對令人抓狂的,所以有c++,java,。net 等應運而生~ linux 系統是純c語言寫的哦~ 也能有vista 那樣美的圖形用戶界面~ 發明c語言的人真的很了不起~ 從匯編的角度看C語言是垃圾,從C語言的角度看其他語言,同樣是垃圾~
其中也包括了懷舊的 MAX 3 界面(3DSMaxR3.cui)。當然如果你有足夠的時間和耐心,也可以自己設計...

❷ 求一個c語言編程題 超過三百行

23根火柴游戲
完整注釋版本

#include<iostream>
#include<string>
#include<ctime>
#define NUM 20
using namespace std;

void main()
{
//規則的輸出
cout<<endl;
cout<<"***************************************************"<<endl;
cout<<"游戲規則:共有23根火柴,2個人依次拿取,每個人每次只"<<endl;
cout<<"能拿1跟或者2跟或者3跟火柴。拿到最後一跟火柴的人算輸"<<endl;
cout<<"****************************************************"<<endl;
cout<<endl;
//變數的定義
int match_num=23; //火柴數目
int *p_match_num; //指向火柴數目的指針
int player = 0; //玩家變數,偶數代表玩家,奇數代表電腦
char player_name[NUM]; //玩家的名字
char player_computer[NUM]="computer";
char judge; //判斷變數,值為'y'時,表示玩家先開局
int put_num=0; //拿走火柴的數目
char *p_player_now;
int *p_put_num; //指向拿走火柴數目的指針
int *p_player;
//指針賦值
p_match_num=&match_num;
p_put_num=&put_num;
p_player=&player;
p_player_now=player_name;
//函數的定義
void match(int* p_match_num,int* p_put_num,int* p_player); //拿走火柴數目
//游戲開始
cout<<"請輸入玩家的名字:";
gets(player_name);
//玩家開局順序的選擇
cout<<"玩家「"<<player_name<<"」選擇拿火柴順序(「F(First)/S(Second)」)";
cin>>judge;
if(judge=='s')
{
p_player_now=player_computer;
player++;
}
cout<<"從「"<<p_player_now<<"」開始游戲。"<<player;
cout<<endl;
//火柴的拿取
while(1)
{
match(p_match_num,p_put_num,p_player);
if(match_num==0)
{
if(player%2==0)
p_player_now=player_name;
else
p_player_now=player_computer;
cout<<"玩家「"<<p_player_now<<"」您輸了!"<<endl;
cout<<player<<endl;
break;
}
}
}

void match(int* p_match_num,int* p_put_num,int* p_player)
{
if((*p_player)%2==0)
{
cout<<"請輸入准備拿走火柴的數目:";
cin>>*p_put_num;
while(*p_put_num!=1 && *p_put_num!=2 && *p_put_num!=3 || *p_match_num-*p_put_num<0)
{
if(*p_put_num!=1 && *p_put_num!=2 && *p_put_num!=3)
{
cout<<"您輸入的數值不合法,拿走的火柴數目只能是 1 或 2 或 3,請重新輸入:";
cin>>*p_put_num;
}
if(*p_match_num-*p_put_num<0)
{
cout<<"您輸入的數值大於剩餘火柴數目,請重新輸入:";
cin>>*p_put_num;
}
}
cout<<"您拿走的火柴數目是: "<<*p_put_num<<endl;
cout<<"剩餘火柴數目是: "<<*p_match_num-*p_put_num<<endl;
}
else
{
srand((int)time(0));
*p_put_num=rand()%3;
while(*p_put_num!=1 && *p_put_num!=2 && *p_put_num!=3 || *p_match_num-*p_put_num<0)
{
*p_put_num=rand()%3;
}
cout<<"computer拿走的火柴數目是:"<<*p_put_num<<endl;
cout<<"剩餘火柴數目是: "<<*p_match_num-*p_put_num<<endl;
}
*p_match_num=*p_match_num-*p_put_num;
cout<<endl;
if(*p_match_num!=0)
(*p_player)++;
}

❸ c語言大作業 最少100行 寫什麼啊

這是以前我自己寫的一個加密解密的程序,一共有175行,不過因為其中寫了兩種加密方法和兩種對應的解密方法,而且用函數將他們區分開來,還用菜單做了選項,所以你只要直接刪除其中一種方法的加解密函數就可以了,這個字元串加解密是對字元串比較全的操作,對你學習c會有幫助,而且也不難看懂,你可以看下,不懂可以通過網路hi問我(encrypt函數是加密函數decrypt是解密函數,數字1和2表示第一種加密方式,第二種加密方式)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
FILE *file=NULL;
void main()
{
void set(char*,int*,int*);
void encrypt1(char*,const int*);
void decrypt1(char*,const int*);
void encrypt2(char*,const int*);
void decrypt2(char*,const int*);
char content[100000]="";
int key1[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int key2[2]={0};
char press='\0';
do
{
printf("*********************************\n");
printf("1.設置加密方法\n");
printf("2.加密方法1\n");
printf("3.加密方法2\n");
printf("4.解密方法1\n");
printf("5.解密方法2\n");
printf("6.退出\n");
printf("*********************************\n");
printf("選擇操作步驟(1-6):\n");
switch(press=getch())
{
case '1':set(content,key1,key2);break;
case '2':encrypt1(content,key1);break;
case '3':encrypt2(content,key2);break;
case '4':decrypt1(content,key1);break;
case '5':decrypt2(content,key2);break;
default:break;
}
}while(press!='6');
if(file!=NULL)
{
rewind(file);
fputs(content,file);
printf("文件或字元串的內容為:\n");
puts(content);
fclose(file);
}
}
void set(char content[100000],int key1[10],int key2[2])
{
long int key;
char ch;
int i;
char str[100]="";
if(file!=NULL)
{
fclose(file);
file=NULL;
}
printf("輸入字元串或者文件完整路徑:");
gets(str);
if(file=fopen(str,"r+"))
{
printf("輸入的是文件完整路徑,內容為:\n");
while(fgetc(file)!=EOF)
{
fseek(file,-1,1);
fgets(content,100000,file);
printf("%s",content);
}
}
else
{
file=fopen("content.txt","w+");
strcpy(content,str);
printf("輸入的是字元串,內容為:\n");
puts(content);
}
printf("\n設置密碼:");
gets(str);
for(i=0;(i<strlen(str))&&(i<10);i++)
*(key1+i)=*(str+i)-'0';
key=atoi(str);
key2[0]=(key%11>=3)?(key%11):3;
for(key2[1]=1,i=0;i<10;i++)
if((*(key1+i)>key2[1])&&(*(key1+i)<key2[0]))
key2[1]=*(key1+i);
}
void encrypt1(char content[100000],const int key1[10])
{
int j,k;
for(j=0,k=0;j<strlen(content);j++)
{
*(content+j)+=*(key1+k);
k++;
if(k==9||*(key1+k)==-1)
k=0;
if(*(content+j)>=122)
*(content+j)%=122;
}
}
void decrypt1(char content[100000],const int key1[10])
{
int j,k;
for(j=0,k=0;j<strlen(content);j++)
{
*(content+j)-=*(key1+k);
k++;
if(k==9||*(key1+k)==-1)
k=0;
if(*(content+j)>=122)
*(content+j)%=122;
}
}
void encrypt2(char content[100000],const int key2[2])
{
char precontent[100000],str[11]="",ch;
int i,j,p;
p=key2[0];
strcpy(precontent,content);
strcpy(content,"");
for(i=0;i<strlen(precontent);)
{
if(strlen(precontent)-i<key2[0])
p=strlen(precontent)-i;
for(j=p-1;j>=0;j--)
*(str+j)=*(precontent+i++);
if(p==key2[0])
{
ch=*(str);
*(str)=*(str+key2[1]);
*(str+key2[1])=ch;
}
else
{
ch=*(str);
*(str)=*(str+p-1);
*(str+p-1)=ch;
}
strcat(content,str);
for(j=0;j<p;j++)
*(str+j)='\0';
if(p!=key2[0])
break;
}
}
void decrypt2(char content[100000],const int key2[2])
{
char precontent[100000],str[11]="",ch;
int i,j,p;
p=key2[0];
strcpy(precontent,content);
strcpy(content,"");
for(i=0;i<strlen(precontent);)
{
if(strlen(precontent)-i<key2[0])
p=strlen(precontent)-i;
for(j=p-1;j>=0;j--)
*(str+j)=*(precontent+i++);
if(p==key2[0])
{
ch=*(str+p-1);
*(str+p-1)=*(str+p-1-key2[1]);
*(str+p-1-key2[1])=ch;
}
else
{
ch=*(str);
*(str)=*(str+p-1);
*(str+p-1)=ch;
}
strcat(content,str);
for(j=0;j<11;j++)
*(str+j)='\0';
if(p!=key2[0])
break;
}
}

❹ C語言老師布置作業讓編寫幾百行的程序,請教各位編寫個什麼好呢

鏈表的插入刪除合並拆分排序夠了

❺ 誰能給我一個C語言四五百行的程序代碼,結業設計用

//學生信息管理系統
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct student
{
char num[20];
char name[20];
int score1;
int score2;
int score3;
}stu[100]={"01","zhangmingming",67,78,82,"02","lichengyou",78,91,88,"03","zhanghuican",68,82,56,"04","wanglu",56,45,77,"05","chendongming",67,38,47};
int main()
{
int i;
int s=5;
void cjtj();
void xxwh();
void xxcx();
void cjpx();
FILE *fp1;
if((fp1=fopen("stu_list","w"))==NULL) /*以只寫的方式打開一個文件stu_list*/
{
printf("Can not open file!\n");
exit(1);
}
fwrite(&stu,sizeof(struct student),5,fp1); /*將stu中的數據寫到文件中*/
fclose(fp1);
do
{
printf("\n");
printf("\n");
printf(" +--------------------+\n");
printf(" |歡迎使用學生管理系統|\n");
printf(" | |\n");
printf(" | 請按照步驟操作 |\n");
printf(" | 1.信息維護 |\n");
printf(" | 2.信息查詢 |\n");
printf(" | 3.成績統計 |\n");
printf(" | 4.成績排序 |\n");
printf(" | 0.退出程序 |\n");
printf(" +--------------------+\n");
printf(" 請選擇您要進行的操作:");
scanf("%d",&i);
if(i==1)
{
xxwh();
}
else if(i==2)
{
xxcx();
}
else if(i==3)
{
cjtj();
}
else if(i==4)
{
cjpx();
}
else
break;
}while(i!=0);
printf("謝謝使用!\n");
return 0;
}
void cjtj() /*成績統計子函數*/
{
char name[20];
system("cls");
printf("請輸入您想統計的課程名稱:\n");
scanf("%s",name);
int q,w,u,s,g,p,k,l,m;
if(strcmp(name,"yuwen")==0)
{
printf("請輸入您想統計的分數段(例60,70):\n");
scanf("%d,%d",&q,&w);

for(u=0;u<5;u++)
{
if((stu[u].score1>=q)&&(stu[u].score1<=w))
printf("%s %s %d %d %d\n",stu[u].num,stu[u].name,stu[u].score1,stu[u].score2,stu[u].score3);
}
}
if(strcmp(name,"shuxue")==0)
{
printf("請輸入您想統計的分數段(例60,70):\n");
scanf("%d,%d",&s,&g);
for(p=0;p<5;p++)
{
if(stu[p].score2>=s&&g>=stu[p].score2)
printf("%s %s %d %d %d\n",stu[p].num,stu[p].name,stu[p].score1,stu[p].score2,stu[p].score3);
}
}
if(strcmp(name,"yingyu")==0)
{
printf("請輸入您想統計的分數段(例60,70):\n");
scanf("%d,%d",&k,&l);
for(m=0;m<5;m++)
{
if(stu[m].score3>=k&&stu[m].score3<=l)
printf("%s %s %d %d %d\n",stu[m].num,stu[m].name,stu[m].score1,stu[m].score2,stu[m].score3);
}
}

return;
}
void xxwh() /* 信息維護子函數*/
{
int y;
int s=5;
void zengjia();
void shanjian();
void xiugai();
do
{
printf(" --------------------\n");
printf(" 歡迎進入信息維護模塊\n");
printf(" 1.增加學生信息 \n");
printf(" 2.刪減學生信息 \n");
printf(" 3.修改學生信息 \n");
printf(" 4.退出本模塊 \n");
printf(" --------------------\n");
printf(" 請輸入您要進行的操作(1-4):");
scanf("%d",&y);
if(y==1)
{
zengjia();
s=s+1;
}
else if(y==2)
{
shanjian();
s=s-1;
}
else if(y==3)
{
xiugai();
}
else
break;
}while(y!=4);
printf("謝謝使用!\n");
return;
}
void zengjia() /*增加學生信息*/
{
struct student student1;
FILE *fp1;
int n=5;
printf("輸入您想添加的學生信息:\n");
scanf("%s %s%d%d%d",student1.num,student1.name,&student1.score1,&student1.score2,&student1.score3);
strcpy(stu[n+1].num,student1.num);
strcpy(stu[n+1].name,student1.name);
stu[n+1].score1=student1.score1;
stu[n+1].score2=student1.score2;
stu[n+1].score3=student1.score3;
if((fp1=fopen("stu_list","r+"))==NULL) /*以讀寫的方式打開一個文件stu_list*/
{
printf("Can not open file!\n");
exit(1);
}
fwrite(&stu,sizeof(struct student),6,fp1); /*將stu中的數據寫到文件中*/
fclose(fp1);
printf("\n");
printf("添加成功!\n");
printf("\n");
printf("\n");
return;
}
void shanjian() /*刪除學生信息*/
{
char a[20];
int h,j,e;
FILE *fp1;
printf("請輸入您想刪除的學生學號:\n");
scanf("%s",a);
for(h=0;h<5;h++)
{
if(strcmp(a,stu[h].num)==0)
j=h;
}
if(j!=4)
{
for(e=h-1;e<5;e++,j++)
{
strcpy(stu[j].num,stu[j+1].num);
strcpy(stu[j].name,stu[j+1].name);
stu[j].score1=stu[j+1].score1;
stu[j].score2=stu[j+1].score2;
stu[j].score3=stu[j+1].score3;
}
}
if((fp1=fopen("stu_list","r+"))==NULL) /*以讀寫的方式打開一個文件stu_list*/
{
printf("Can not open file!\n");
exit(1);
}
fwrite(&stu,sizeof(struct student),6,fp1); /*將stu中的數據寫到文件中*/
fclose(fp1);
printf("\n");
printf("刪除成功!\n");
printf("\n");
printf("\n");
return;
}
void xiugai() /*修改學生信息*/
{
char b[20];
int c,n=5;
FILE *fp1;
struct student student2;
printf("請輸入您想修改的學生學號:\n");
scanf("%s",b);
for(c=0;c<n;c++)
{
if(strcmp(b,stu[c].num)==0)
{
printf("請輸入修改後的學生信息:\n");
scanf("%s %s%d%d%d",student2.num,student2.name,&student2.score1,&student2.score2,&student2.score3);
strcpy(stu[c].num,student2.num);
strcpy(stu[c].name,student2.name);
stu[c].score1=student2.score1;
stu[c].score2=student2.score2;
stu[c].score3=student2.score3;
}
} if((fp1=fopen("stu_list","r+"))==NULL) /*以讀寫的方式打開一個文件stu_list*/
{
printf("Can not open file!\n");
exit(1);
}
fwrite(&stu,sizeof(struct student),6,fp1); /*將stu中的數據寫到文件中*/
fclose(fp1);
fclose(fp1);
printf("\n");
printf("修改成功!\n");
printf("\n");
printf("\n");
return;
}
void cjpx() /*排序函數*/
{
int z,x,c,v,o;
struct student t;
do
{
printf("\n");
printf("\n");
printf("[1]按升序排序:\n");
printf("[2]按降序排序:\n");
printf("[3]返回\n");
printf("請選擇:");
scanf("%d",&z);
if(z==1)
{
printf("選擇的科目:");
printf("[1]語文:[2]數學:[3]英語:");
scanf("%d",&x);
if(x==1)
{
for(c=1;c<5;c++)
for(v=0;v<5-c;v++)

if(stu[v].score1>stu[v+1].score1)
{
t=stu[v];
stu[v]=stu[v+1];
stu[v+1]=t;
}
for(o=0;o<5;o++)
printf("%s %s %d %d %d\n",stu[o].num,stu[o].name,stu[o].score1,stu[o].score2,stu[o].score3);
}
else if(x==2)
{
for(c=1;c<5;c++)
for(v=0;v<5-c;v++)
if(stu[v].score2>stu[v+1].score2)
{
t=stu[v];
stu[v]=stu[v+1];
stu[v+1]=t;
}
for(o=0;o<5;o++)
printf("%s %s %d %d %d\n",stu[o].num,stu[o].name,stu[o].score1,stu[o].score2,stu[o].score3);
}
else if(x==3)
{
for(c=1;c<5;c++)
for(v=0;v<5-c;v++)
if(stu[v].score3>stu[v+1].score3)
{
t=stu[v];
stu[v]=stu[v+1];
stu[v+1]=t;
}
for(o=0;o<5;o++)
printf("%s %s %d %d %d\n",stu[o].num,stu[o].name,stu[o].score1,stu[o].score2,stu[o].score3);
}
}
else
if(z==2)
{
printf("選擇的科目:");
printf("[1]語文:[2]數學:[3]英語:");
scanf("%d",&x);
if(x==1)
{
for(c=1;c<5;c++)
for(v=0;v<5-c;v++)
if(stu[v].score1<stu[v+1].score1)
{
t=stu[v+1];
stu[v+1]=stu[v];
stu[v]=t;
}
for(o=0;o<5;o++)
printf("%s %s %d %d %d\n",stu[o].num,stu[o].name,stu[o].score1,stu[o].score2,stu[o].score3);
}
else
if(x==2)
{
for(c=1;c<5;c++)
for(v=0;v<5-c;v++)

if(stu[v].score2<stu[v+1].score2)
{
t=stu[v+1];
stu[v+1]=stu[v];
stu[v]=t;
}
for(o=0;o<5;o++)
printf("%s %s %d %d %d\n",stu[o].num,stu[o].name,stu[o].score1,stu[o].score2,stu[o].score3);
}
else
if(x==3)
{
for(c=1;c<5;c++)
for(v=0;v<5-c;c++)

if(stu[v].score3<stu[v+1].score3)
{
t=stu[v+1];
stu[v+1]=stu[v];
stu[v]=t;
}
for(o=0;o<5;o++)
printf("%s %s %d %d %d\n",stu[o].num,stu[o].name,stu[o].score1,stu[o].score2,stu[o].score3);
}
}
else
break;
}while(z!=3);
printf("\n");
printf("\n");
return;
}
void xxcx() /*信息查詢子函數*/
{
int g,i;
char m[20];
system("cls");
do
{
printf("[1]查詢學生信息:\n");
printf("[2]退出查詢:\n");
printf("請選擇:");
scanf("%d",&g);
if(g==1)
{
printf("請輸入學號:");
scanf("%s",m);
for(i=0;i<5;i++)
{
if(strcmp(m,stu[i].num)==0)
{
printf("*********\n");
printf("學號:%s\n",stu[i].num);
printf("姓名:%s\n",stu[i].name);
printf("語文:%d\n",stu[i].score1);
printf("數學:%d\n",stu[i].score2);
printf("英語:%d\n",stu[i].score3);
printf("\n");
printf("\n");
}
}
}
else
break;
}while(g!=2);
printf("查找完畢!\n");
system("pause");
return;
}

❻ c語言游戲編程

你錯了~
理論上說,其他語言做到的c語言一定能夠做到~而且效率高得多,只不過其他語言一句話就能做到的,C語言可能要上百行代碼~
c語言時代,一個大軟體
動輒幾十萬行,幾百萬行代碼,其中出一個錯誤,是絕對令人抓狂的,所以有c++,java,。net
等應運而生~
linux
系統是純c語言寫的哦~
也能有vista
那樣美的圖形用戶界面~
發明c語言的人真的很了不起~
從匯編的角度看C語言是垃圾,從C語言的角度看其他語言,同樣是垃圾~
其中也包括了懷舊的
MAX
3
界面(3DSMaxR3.cui)。當然如果你有足夠的時間和耐心,也可以自己設計...

❼ 求3百行左右可在VC運行的C語言程序的編碼,希望是原創的

無任何要求的很簡單的

你自己把一段小說弄下來
定義個幾個字元串
然後列印出來即可~
湊個300行隨便咯

你不說要求,誰知道怎麼做。

❽ 給我一個C語言程序要求百行以上,謝謝

紅黑樹的一個演示程序,不一定完全正確
大概300+吧

// Copyright 1988-2006 By Zor X. Liu

#include <stdio.h>
#include <conio.h>

enum Color { red,black };

struct RBTNode
{
int dat;
Color c;
RBTNode *p,*l,*r;
};

RBTNode *root,*nil;

RBTNode* Insert(int);
void Delete(RBTNode*);
RBTNode* Successor(RBTNode*);
RBTNode* Minium(RBTNode*);
RBTNode* Search(int);
void LeftRotate(RBTNode*);
void RightRotate(RBTNode*);
void InorderWalk(RBTNode*);
void PreorderWalk(RBTNode*);
void Free(RBTNode*);

int main()
{
nil=new RBTNode;
nil->c=black,nil->dat=0;
nil->p=nil->r=nil->l=NULL;

RBTNode *tmp;
int choice,dat;
while(true)
{
clrscr();
printf("------------------------------\n");
printf("Current:");InorderWalk(root);printf("\n");
printf("------------------------------\n");
printf(" 1.Insert\n");
printf(" 2.Delete\n");
printf(" 3.Preorder Walk\n");
printf(" q.Quit\n");
printf("------------------------------\n");
do {
choice=getch();
} while(choice!='q'&&(choice>'3'||choice<'1'));
if(choice=='q')
break;
if(choice=='1'||choice=='2')
{
printf("Data:");
scanf("%d",&dat);
}
switch(choice)
{
case '1':
Insert(dat);
printf("Inserted.\n");
break;
case '2':
tmp=Search(dat);
if(!tmp)
{
printf("Cannot find it.\n");
break;
}
Delete(tmp);
printf("Deleted.\n");
break;
case '3':
PreorderWalk(root);
break;
}
getch();
}
return 0;
}

void InorderWalk(RBTNode* x)
{
if(x!=nil&&x)
{
InorderWalk(x->l);
printf("%d",x->dat);
if(x->c==red)
printf("r ");
else
printf("b ");
InorderWalk(x->r);
}
}

void PreorderWalk(RBTNode* x)
{
if(x!=nil&&x)
{
printf("%d",x->dat);
if(x->c==red)
printf("r ");
else
printf("b ");
PreorderWalk(x->l);
PreorderWalk(x->r);
}
}

void Free(RBTNode* x)
{
if(x!=nil&&x)
{
Free(x->l);
Free(x->r);
delete x;
}
}

RBTNode* Search(int dat)
{
RBTNode *x=root;
if(root)
{
while(x!=nil)
{
if(dat==x->dat)
return x;
else
if(dat>x->dat)
x=x->r;
else
x=x->l;
}
}
return NULL;
}

RBTNode* Minium(RBTNode* x)
{
while(x->l!=nil)
x=x->l;
return x;
}

RBTNode* Successor(RBTNode* x)
{
if(x->r)
return Minium(x->r);

RBTNode *y=x->p;
while(y&&x==y->r)
{
x=y;
y=y->p;
}
return y;
}

void LeftRotate(RBTNode* x)
{
RBTNode *y=x->r,*z=x->p;
if(y!=nil)
{
x->p=y;
x->r=y->l;y->l->p=x;
y->p=z;
y->l=x;
if(y->p)
if(x==y->p->l)
y->p->l=y;
else
y->p->r=y;
else
root=y;
}
}

void RightRotate(RBTNode* x)
{
RBTNode *y=x->l,*z=x->p;
if(y!=nil)
{
x->p=y;
x->l=y->r;y->r->p=x;
y->p=z;
y->r=x;
if(y->p)
if(y->p->l==x)
y->p->l=y;
else
y->p->r=y;
else
root=y;
}
}

RBTNode* Insert(int dat)
{
RBTNode *n;
n=new RBTNode;
n->dat=dat,n->c=red;
n->p=NULL,n->l=n->r=nil;

if(!root)
{
root=n;
n->c=black;
return n;
}

RBTNode *x=root,*y=NULL;
while(x!=nil)
{
y=x;
if(dat>x->dat)
x=x->r;
else
x=x->l;
}
n->p=y;
if(dat>y->dat)
y->r=n;
else
y->l=n;

if(y->c==red)
{
x=n;
while(x->p->p&&x->c==red&&x->p->c==red)
{
if(x->p->p->l==x->p)
{
y=x->p->p->r;
if(y->c==red)
{
x->p->p->c=red;
x->p->c=y->c=black;
x=x->p->p;
}
else
{
if(x==x->p->r)
{
LeftRotate(x->p);
x=x->l;
}
x->p->c=black;
x->p->p->c=red;
RightRotate(x->p->p);
}
}
else
{
y=x->p->p->l;
if(y->c==red)
{
x->p->p->c=red;
x->p->c=y->c=black;
x=x->p->p;
}
else
{
if(x==x->p->l)
{
RightRotate(x->p);
x=x->r;
}
x->p->c=black;
x->p->p->c=red;
LeftRotate(x->p->p);
}
}
}
}
root->c=black;
}

void Delete(RBTNode* x)
{
RBTNode *y,*z;
if(x->l==nil||x->r==nil)
y=x;
else
y=Successor(x);

if(y->l!=nil)
z=y->l;
else
z=y->r;

z->p=y->p;
if(y->p)
if(y==y->p->r)
y->p->r=z;
else
y->p->l=z;
else
root=z,z->p=NULL;

if(y!=x)
x->dat=y->dat;
if(y->c==black)
{
x=z;
while(x!=root&&x->c==black)
{
if(x==x->p->l)
{
z=x->p->r;
if(z->c==red)
{
x->p->c=red;
z->c=black;
LeftRotate(x->p);
}
if(z->c==black)
{
if(z->l->c==z->r->c==black)
{
z->c=red;
x=x->p;
}
else if(z->l->c==red&&z->r->c==black)
{
RightRotate(z);
z=z->p;
}
if(z->r->c==red)
{
z->r->c=black;
z->c=z->p->c;
z->p->c=black;
LeftRotate(z->p);
x=root;
}
}
}
else
{
z=x->p->l;
if(z->c==red)
{
x->p->c=red;
z->c=black;
RightRotate(x->p);
}
if(z->c==black)
{
if(z->r->c==z->l->c==black)
{
z->c=red;
x=x->p;
}
else if(z->r->c==red&&z->l->c==black)
{
LeftRotate(z);
z=z->p;
}
if(z->l->c==red)
{
z->l->c=black;
z->c=z->p->c;
z->p->c=black;
RightRotate(z->p);
x=root;
}
}
}
}
}
delete y;
}

❾ 編寫一個幾百行代碼的C語言程序 存儲數據用結構體還是鏈表好

要看你是怎樣應用了。你要動態分配,那肯定是鏈表了。如果你要便於直接訪問,那就結構體數組。

❿ C 幾百行代碼python卻幾行c 值得嗎

  1. 不要去比較這些,沒有任何意義。存在即合理,C語言有C語言擅長的,Python有Python擅長的領域。

  2. 對於程序員來說,語言不是障礙,更重要的是邏輯思維、演算法、排錯能力和大局觀。

最後,別再糾結這類問題了。

熱點內容
c語言期末試卷 發布:2025-07-17 05:49:58 瀏覽:404
64位access資料庫 發布:2025-07-17 05:35:58 瀏覽:374
php文件的相對路徑 發布:2025-07-17 05:34:22 瀏覽:711
矢量的叉乘運演算法則 發布:2025-07-17 05:29:41 瀏覽:661
dell雲存儲伺服器 發布:2025-07-17 05:21:06 瀏覽:255
銑床怎麼編程 發布:2025-07-17 05:20:29 瀏覽:776
sql11oracle 發布:2025-07-17 05:15:39 瀏覽:744
全國各地移動dns伺服器ip地址 發布:2025-07-17 05:07:47 瀏覽:312
sdvn加密 發布:2025-07-17 05:01:36 瀏覽:739
怎麼提取電腦緩存中的音樂 發布:2025-07-17 04:53:14 瀏覽:27