在线等~急求写个C语言数据结构程序!!! 高分求一个C语言数据结构程序题
\u7528C\u8bed\u8a00\u548c\u6570\u636e\u7ed3\u6784\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u7a0b\u5e8f\u8fd9\u4e2a\u6d89\u53ca\u5230\u7684\u6570\u636e\u7ed3\u6784\u4e8c\u53c9 \u5177\u4f53\u7b97\u6cd5\u5e94\u8be5\u5148\u5bf9\u8f93\u5165\u8fdb\u6765\u7684\u6570\u5b57\u8fdb\u884c\u4e8c\u53c9\u6811\u7684\u6784\u9020\uff0c\u7136\u540e\u518d\u7528\u540c\u4e00\u79cd\u904d\u5386\u65b9\u5f0f\u5bf9\u6240\u6709\u6784\u9020\u7684\u4e8c\u53c9\u6811\u8fdb\u884c\u904d\u5386\u8f93\u51fa\u3002
#include
#include
#include
#include
#include
#include
#include
void menu()
{
system("cls");
printf("********************\u6587\u672c\u8bfb\u53d6\u4e0e\u67e5\u8be2********************\n");
printf("1.\u7edf\u8ba1\u6587\u672c\u4e2d\u5355\u8bcd\u7684\u4e2a\u6570\n");
printf("2.\u8f93\u5165\u6307\u5b9a\u7684\u5355\u8bcd\u6216\u77ed\u8bed\u67e5\u627e\u5b83\u7684\u51fa\u73b0\u6b21\u6570\n");
printf("3.\u8f93\u5165\u6307\u5b9a\u7684\u5355\u8bcd\u6216\u77ed\u8bed\u66ff\u6362\n");
printf("4.\u63a8\u51fa\n");
printf("\u8bf7\u8f93\u5165\u9009\u62e9\uff1a");
}
class Text
{
public:
void birth()
{
FILE *fp;
char ch;
int i,j,n;
fp=fopen("text.txt","rb+");
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++)
{
ch=fgetc(fp);
if(ch=='$')
{
n=i;
i=1000;
break;
}
a[i][j]=ch;
if(ch=='.' || ch=='?' || ch=='!')
{
break;
}
}
}
fclose(fp);
}
int find()
{
int i,j,m=0;
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++)
{
if(a[i][j]==' ')
{
m++;
}
else if(a[i][j]=='.')
{
m++;
break;
}
}
}
return m;
}
void findwords(char *b)
{
char c[1000],chb,chc;
int m,i,j,s,l,x;
m=0;
s=strlen(b);
for(i=0;i<1000;i++)
{
x=0;
for(j=0;j<1000;j++)
{
if(a[i][j]=='.' || a[i][j]=='?' || a[i][j]=='!')
{
if(x!=0)
{
print(i,j,s,x,1);
}
break;
}
if(abs(b[0]-a[i][j])%32==0 && a[i][j-1]==' ')
{
chb='\0';
chc='\0';
if(a[i][j+s]==' ' || a[i][j+s]==',' || a[i][j+s]=='.' || a[i][j+s]=='?' || a[i][j+s]=='!' || a[i][j+s]==':' || a[i][j+s]==';')
{
for(l=0;l<s;l++)
{
c[l]=a[i][j+l];
}
for(l=0;l<s;l++)
{
chb=chb+b[l];
}
for(l=0;l<s;l++)
{
chc=chc+c[l];
}
if(abs(chb-chc)%32==0)
{
m++;
print(i,j,s,x,0);
x=j+s+1;
}
}
}
if(abs(b[0]-a[i][j])%32==0 && a[i][j-1]=='\0')
{
chb='\0';
chc='\0';
if(a[i][j+s]==' ' || a[i][j+s]==',' || a[i][j+s]=='.' || a[i][j+s]=='?' || a[i][j+s]=='!' || a[i][j+s]==':' || a[i][j+s]==';')
{
for(l=0;l<s;l++)
{
c[l]=a[i][j+l];
}
for(l=0;l<s;l++)
{
chb=chb+b[l];
}
for(l=0;l<s;l++)
{
chc=chc+c[l];
}
if(abs(chb-chc)%32==0)
{
m++;
print(i,j,s,x,0);
x=j+s+1;
}
}
}
}
}
printf("\u8be5\u5355\u8bcd\u6216\u77ed\u8bed\u51fa\u73b0\u7684\u6b21\u6570:");
printf("%d\n",m);
}
void exchange(char *b,char *bb)
{
char c[1000],chb,chc;
int m,i,j,s,l,x;
m=0;
s=strlen(b);
for(i=0;i<1000;i++)
{
x=0;
for(j=0;j<1000;j++)
{
if(a[i][j]=='.' || a[i][j]=='?' || a[i][j]=='!')
{
if(x!=0)
{
print(i,j,s,x,1);
}
break;
}
if(abs(b[0]-a[i][j])%32==0 && a[i][j-1]==' ')
{
chb='\0';
chc='\0';
if(a[i][j+s]==' ' || a[i][j+s]==',' || a[i][j+s]=='.' || a[i][j+s]=='?' || a[i][j+s]=='!' || a[i][j+s]==':' || a[i][j+s]==';')
{
for(l=0;l<s;l++)
{
c[l]=a[i][j+l];
}
for(l=0;l<s;l++)
{
chb=chb+b[l];
}
for(l=0;l<s;l++)
{
chc=chc+c[l];
}
if(abs(chb-chc)%32==0)
{
m++;
for(l=j;l<j+s;l++)
{
a[i][l]=bb[l-j];
}
print(i,j,s,x,0);
x=j+s+1;
j=j+s+1;
}
}
}
if(abs(b[0]-a[i][j])%32==0 && a[i][j-1]==' ')
{
chb='\0';
chc='\0';
if(a[i][j+s]==' ' || a[i][j+s]==',' || a[i][j+s]=='.' || a[i][j+s]=='?' || a[i][j+s]=='!' || a[i][j+s]==':' || a[i][j+s]==';')
{
for(l=0;l<s;l++)
{
c[l]=a[i][j+l];
}
for(l=0;l<s;l++)
{
chb=chb+b[l];
}
for(l=0;l<s;l++)
{
chc=chc+c[l];
}
if(abs(chb-chc)%32==0)
{
m++;
for(l=j;l<j+s;l++)
{
a[i][l]=bb[l-j];
}
print(i,j,s,x,0);
x=j+s+1;
j=j+s+1;
}
}
}
}
}
printf("\u8be5\u5355\u8bcd\u6216\u77ed\u8bed\u51fa\u73b0\u7684\u6b21\u6570:");
printf("%d\n",m);
}
void print(int i,int x,int y,int z,int k)
{
int j;
if(k==0)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
for(j=z;j<x;j++)
{
printf("%c",a[i][j]);
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED);
for(j=x;j<x+y;j++)
{
printf("%c",a[i][j]);
}
printf(" ");
}
if(k==1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
for(j=z;j<=x;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
}
private:
char a[1000][1000];
};
void main()
{
Text text;
int j,choice;
char s[1000],ss[1000],con;
r1: menu();
text.birth();
cin>>choice;
if(choice==1)
{
system("cls");
j=text.find();
printf("\u5355\u8bcd\u51fa\u73b0\u7684\u6b21\u6570\uff1a");
printf("%d\n",j);
printf("\u4f60\u60f3\u7ee7\u7eed\u5417\uff1f");
con=getch();
if((con=='Y') || (con=='y'))
{
goto r1;
}
if((con=='N') || (con=='n'))
{
return;
}
}
if(choice==2)
{
r2: system("cls");
printf("\u8bf7\u8f93\u5165\u6240\u8981\u67e5\u8be2\u7684\u5355\u8bcd\u6216\u77ed\u8bed\uff1a");
gets(s);
text.findwords(s);
printf("\u4f60\u60f3\u7ee7\u7eed\u5417\uff1f");
con=getch();
if((con=='Y') || (con=='y'))
{
goto r2;
}
if((con=='N') || (con=='n'))
{
goto r1;
}
}
if(choice==3)
{
r3: system("cls");
printf("\u8bf7\u8f93\u5165\u8981\u66ff\u6362\u7684\u5355\u8bcd");
gets(s);
printf("\u8bf7\u8f93\u5165\u6240\u66ff\u6362\u7684\u5355\u8bcd");
gets(ss);
text.exchange(s,ss);
printf("\u4f60\u60f3\u7ee7\u7eed\u5417\uff1f");
con=getch();
if((con=='Y') || (con=='y'))
{
goto r3;
}
if((con=='N') || (con=='n'))
{
goto r1;
}
}
if(choice==4)
{
system("cls");
printf("\u4f60\u60f3\u9000\u51fa\u5417\uff1f");
con=getch();
putchar(10);
if((con=='Y') || (con=='y'))
{
return;
}
if((con=='N') || (con=='n'))
{
goto r1;
}
}
}
\u8bf4\u660e\u8981\u5728\u5de5\u7a0b\u4e0b\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6text.txt\u628a\u8981\u8bfb\u7684\u4e1c\u897f\u653e\u5728\u91cc\u9762\u5c31\u53ef\u4ee5\u4e86
代码都有注释的,相信你能看明白。后边付有测试数据及测试结果。
有问题Hi我哈:)
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
/* 链表节点结构体 */
typedef struct _Node {
int data;
struct _Node *next;
} Node;
/* 创建链表 */
void create_list(Node *head)
{
Node *newNode = NULL;
Node *tempNode = NULL;
int input = 0;
if(NULL == head)
{
printf("参数错误,程序结束!");
exit(0);
}
tempNode = head;
printf("请输入需要创建的链表值(输入0结束)\n");
scanf("%d", &input);
while(input != 0)
{
newNode = malloc(sizeof(Node));
if (newNode == NULL)
{
printf("参数错误,程序结束!");
exit(0);
}
newNode->data = input;
newNode->next = NULL;
tempNode->next = newNode;
tempNode = newNode;
scanf("%d", &input);
}
}
/* 找出最大节点 */
void max_node_search(Node *head)
{
int max_value = 0; /* 保存节点中的最大值 */
Node *tempNode = NULL; /* 节点指针,用来遍历链表 */
if(NULL == head)
{
printf("参数错误,程序结束!");
exit(0);
}
tempNode = head->next; /* 当前节点初始化 */
max_value = tempNode->data; /* 保存当前节点的值 */
/* 顺序遍历链表,找到最大值的节点 */
while(tempNode)
{
/* 最大值与当前节点的值作比较 */
if(max_value < tempNode->data)
{
max_value = tempNode->data; /* 保存最大值 */
}
tempNode = tempNode->next; /* 当前节点变更 */
}
printf("最大节点的值: %d\n", max_value); /* 输出最大节点的值 */
}
/* 偶数、奇数查找,如果当前节点值是偶数,则将其与后继节点交换,
如果当前节点为奇数,则删除其后继节点
*/
void list_make_up(Node *head)
{
Node *tempNode = NULL; /* 节点指针,用来遍历链表 */
Node *delNode = NULL; /* 被删除节点的指针 */
int temp = 0;
if(NULL == head)
{
printf("参数错误,程序结束!");
exit(0);
}
tempNode = head->next;
/* 顺序遍历链表 */
while(tempNode)
{
/* 如果已经是最后一个节点,则退出 */
if (tempNode->next == NULL)
break;
if (tempNode->data%2 == 0) /* 偶数判断 */
{
/* 将当前节点与后继节点的值交换 */
temp = tempNode->data;
tempNode->data = tempNode->next->data;
tempNode->next->data = temp;
tempNode = tempNode->next;
continue; /* 继续下一个节点 */
}
if (tempNode->data%2 != 0) /* 奇数判断 */
{
/* 将后继节点删除 */
delNode = tempNode->next;
tempNode->next = delNode->next;
free(delNode); /* 节点被删除,占用内存被释放 */
delNode = NULL;
tempNode = tempNode->next;
continue; /* 继续下一个节点 */
}
}
/* 打印整理后的链表值 */
tempNode = head->next;
printf("整理后的链表值: ");
/* 遍历整个链表,输出节点值 */
while(tempNode)
{
printf("%d ", tempNode->data);
tempNode = tempNode->next;
}
printf("\n");
}
/* 测试函数main */
int main()
{
Node head;
Node *tempNode = NULL;
Node *delNode = NULL;
head.data = 0;
head.next = NULL;
create_list(&head); /* 创建链表 */
max_node_search(&head); /* 查找最大值 */
list_make_up(&head); /* 整理链表 */
/* 释放内存 */
tempNode = head.next;
while(tempNode)
{
delNode = tempNode;
tempNode = delNode->next;
free(delNode);
}
return 0;
}
测试数据
①
12 4 8 17 76
最大节点值:76
链表:24 8 17 76 12s
②
12 7 3 8 5
最大节点值:12
链表: 7 3 8 5 12
③
7 12 34 17 19
最大节点值:34
链表:7 17 19 34
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N_NODE 15 /*单链表中的结点个数*/
typedef struct node{
int data;
struct node *next;
} node;
node *creat(int n) /*创建一个有n个结点的单链表*/
{
int i;
node *s,*p,*h=NULL;
for (i = 0; i<n; i++) {
p=(node *)malloc(sizeof(node));
p->next=NULL;
if (!h) h=p;
else s->next=p;
s=p;
p->data=rand()%100; /*链表结点的数据域用随机数填充,可以在此修改为从键盘输入*/
}
return h;
}
node *maxn(node *h) /*返回最大值结点*/
{
node *ma=h;
h=h->next;
while (h)
{
if (ma->data<h->data) {
ma=h;
}
h=h->next;
}
return ma;
}
node *del(node *h,node *todel) /*删除链表h中的todel结点*/
{
node *p=h;
if (h==todel) {
p=h->next;
free(todel);
}
else p->next=del(h->next,todel);
return p;
}
void prt(node *h) /*输出链表*/
{
while (h)
{
printf("%d ",h->data);
h=h->next;
}
putchar('\n');
}
void fun(node *h) /*完成要求的过程,奇数就删除,否则就调换位置*/
{
node *max=maxn(h);
int t;
printf("原始单链表为:");
prt(h);
printf("最大值:%d\n",max->data);
if (max&&max->data%2) {
h=del(h,max);
}
else if (max&&max->data%2==0) {
t=max->data;
max->data=max->next->data;
max->next->data=t;
}
printf("处理后的结果是:");
prt(h);
}
int main(void)
{
node *ht=NULL;
srand((unsigned int )time(NULL));
ht=creat(N_NODE);
fun(ht);
return 0;
}
//---------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
struct node
{
int x;
node *next;
}*link,*max,*start,t;
node* creatlinks(int n)
{
node *head=NULL,*first=NULL,*ptr=NULL;
head=first=(node*)malloc(sizeof(node));
scanf("%d",&first->x);
for ( int i = 1; i < n; i++)
{
ptr = (node*)malloc(sizeof(node));
scanf("%d",&ptr->x);
first->next = ptr;
first = ptr;
ptr = NULL;
}
first->next = NULL;
return head;
}
int main()
{
int n;
t.x=0;
max=&t;
scanf("%d",&n);
start=link=creatlinks(n);
while(link!=NULL)
{
if(link->x>max->x)
max=link;
link=link->next;
}
printf("max=%d\n",max->x);
if(max->x&1)
{
max->next=max->next->next;
}
else
{
int temp;
temp=max->x;
max->x=max->next->x;
max->next->x=temp;
}
link=start;
while(link!=NULL)
{
printf("%d\n",link->x);
link=link->next;
}
}
//
input:
5
132
45189
51
5163
656
output:
max=45189
132
45189
5163
656
input:
6
4165
15
54154
655
156
85
output:
max=54154
4165
15
655
54154
156
85
我不是来挣分的,我只想提醒楼上诸位:悬赏分150,追加分100.诸位难道非常想要这个分数么?
绛旓細鍐欎簡涓涓紝浠婂ぉ鐧惧害琚粦浜嗭紝鎬绘槸鎵撲笉寮銆傜幇鍦ㄤ紶缁欎綘鐪嬬湅閭e搱銆備唬鐮侀兘鏈夋敞閲婄殑锛岀浉淇′綘鑳界湅鏄庣櫧銆傚悗杈逛粯鏈夋祴璇鏁版嵁鍙婃祴璇曠粨鏋溿傛湁闂Hi鎴戝搱:)include <stdio.h> include <stdlib.h> include <malloc.h> include <string.h> /* 閾捐〃鑺傜偣缁撴瀯浣 */ typedef struct _Node { int data;struct _...
绛旓細q->next = L->next;//璁╁熬缁撶偣鎸囧悜澶寸粨鐐圭殑涓嬩竴涓紝鍗崇涓涓汉鐨勪綅缃紝鍗曞悜寰幆閾捐〃鍒涘缓瀹屾垚 q = L->next;//璁﹒鎸囧悜澶寸粨鐐圭殑涓嬩竴涓 while (q->next != q)//鍙墿涓涓厓绱犳椂锛岄鍑哄惊鐜 { for (i=1; i<k-1; ++i){q = q->next;}//q鎸囧悜鍒犻櫎鑺傜偣鐨勫墠涓涓 s = q->next;/...
绛旓細浣滀负绾挎х粨鏋勭殑寮绡囩珷鑺,绾挎ц〃涓绔鍦ㄧ嚎鎬х粨鏋勭殑瀛︿範涔冭嚦鏁翠釜鏁版嵁缁撴瀯瀛︾鐨勫涔犱腑,鍏朵綔鐢ㄩ兘鏄笉鍙綆浼扮殑銆傚湪杩欎竴绔,绗竴娆$郴缁熸у湴寮曞叆閾惧紡瀛樺偍鐨勬蹇,閾惧紡瀛樺偍姒傚康灏嗘槸鏁翠釜鏁版嵁缁撴瀯瀛︾鐨勯噸涓箣閲,鏃犺鍝竴绔犻兘娑夊強鍒颁簡杩欎釜姒傚康銆傛讳綋鏉ヨ,绾挎ц〃涓绔犲彲渚涜冩煡鐨勯噸瑕佽冪偣鏈変互涓嬪嚑涓柟闈:1.绾挎ц〃鐨勭浉鍏冲熀鏈蹇...
绛旓細include <stdio.h>#include <malloc.h>typedef struct st{ int id; struct st *next; struct st *tailST;}ST;ST *getSTS(int len);//鑾峰彇涓涓摼琛紝鑺傜偣涓暟涓簂en锛岃繑鍥為摼琛ㄩ鍦板潃ST *getST(ST *headST,int con);//鑾峰彇绗琧on涓妭鐐箆oid printfST(ST *headST);//鎵撳嵃閾捐〃int...
绛旓細棰樼洰濡備笅:涓や釜涓鍏冨椤瑰紡鐩镐箻鐨勭畻娉昅(x)=A(x)*B(x)=A(x)*[b1X^e1+b2X^e2+...+bnX^en]涔熷氨鏄疉(x)鍜孊(x)閮戒釜鏄竴涓竴鍏冨椤瑰紡銆備緥濡:M(x)=A(x)*B(x)=(2x^2+3x^3+4x^4)*(5x^2+6x^3+7... 棰樼洰濡備笅: 涓や釜涓鍏冨椤瑰紡鐩镐箻鐨勭畻娉 M(x)=A(x)*B(x) =A(x)*[b1X^e1+b2X^...
绛旓細void nz(node *DLlist){Node *p,*q,*t;t=DLlist; //t鎸囧悜DLListp = t->next; //p鎸囧悜t鐨勪笅涓涓猼->next = NULL; //t鐨刵ext涓虹┖while (p!=NULL){q=p->next; //q鎸囧悜p鐨勪笅涓涓猵->next=t->next; //p鐨勪笅涓涓寚鍚憈鐨勪笅涓涓猼->next = p; //t鐨勪笅涓...
绛旓細while(p->next!=NULL){ n++;p=p->next;} return(n);} void DispList(LinkList *L)//杈撳嚭绾挎ц〃 { LinkList *p=L->next;while(p!=NULL){ printf("%c",p->data);p=p->next;} } int GetElem(LinkList *L,int i,ElemType &e)//姹傜嚎鎬ц〃涓煇涓鏁版嵁鍏冪礌鍊 { int j=0;...
绛旓細include<iostream> include<windows.h> include<process.h> using namespace std;int flag = 0;//鎺у埗鏄惁鍋滄鍑婚紦 int i = 0;//鎺у埗鑺卞湪璋佹墜閲 int n;//娓告垙浜烘暟 int stopgameflag = 0;//鏄惁缁撴潫娓告垙 { while(!stopgameflag){ while(flag == 0){ i++;if (i == n){ i = 0;...
绛旓細include <iostream.h> include <stdio.h> include <malloc.h> define MaxNode 100 typedef char DataType;typedef struct node { DataType data;struct node lchild;struct node rchild;}BiTNode,BiTree;void CreateBiTree(BiTree bt)//寤虹珛涓涓簩鍙夋爲 { char ch;//ch=getchar();scanf("%c",...
绛旓細//str.c include"stdio.h"include"str.h"void main(){ int n,flag=0;int i=4,j=6;char *str,*sub;str=(char*)malloc(sizeof(char)*100);sub=(char*)malloc(sizeof(char)*100);printf(" 涓插瓙绯荤粺 \n");printf("***\n");printf("* 1---杈撳叆瀛椾覆 ...