解题思路:
因为不能确定接收字符串长度所以觉得使用链表会更好一些




注意事项:

提交之后时间超限



参考代码:#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区