解题思路:
因为不能确定接收字符串长度所以觉得使用链表会更好一些
注意事项:
提交之后时间超限
参考代码:#include<stdio.h>
#include <stdlib.h>
//写一个函数,使给定的一个二维数组(3×3)转置,即行列互换。
typedef struct NODE{
char a;
struct NODE *next;
}Node;
Node* create();
void cpy(Node*,Node*);
void print(Node *);
void freeNode(Node*);
int main()
{
Node *head1=NULL,*head2=NULL;
head1=create();head2=create();
cpy(head1,head2);
print(head1);
freeNode(head1);
system("pause");
return 0;
}
Node* create(){
Node *head=NULL,*temp,*add;
char a;
while((a=getchar())!='\n'){
add=(Node*)malloc(sizeof(Node));
add->a=a;
if(head==NULL){
head=add;
temp=add;
}
else{
temp->next=add;
temp=add;
}
add->next=NULL;
}
return head;
}
void cpy(Node* head1,Node *head2){
Node *headcpy=NULL;
while(head1){
headcpy=head1;
head1=head1->next;
}
headcpy->next=head2;
// print(headcpy);
}
void print(Node *head){
while(head){
printf("%c",head->a);
head=head->next;
}
}
void freeNode(Node* head){
Node* temp;
while(head){
temp=head;
head=head->next;
free(temp);
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:520 |
哥德巴赫曾猜测 (C语言代码)浏览:2348 |
C语言程序设计教程(第三版)课后习题9.1 (C语言代码)浏览:681 |
printf基础练习2 (C语言代码)浏览:618 |
简单的a+b (C语言代码)浏览:581 |
罗列完美数 (C语言代码)浏览:491 |
核桃的数量 (C语言代码)浏览:872 |
Quadratic Equation (C语言代码)浏览:988 |
整除问题 (C语言代码)浏览:526 |
数列有序 (C语言代码)浏览:935 |