Sequential list Merge C language recursive version--I'll do a little bit of programming

Source: Internet
Author: User

The last day of the holiday, busy no matter how to make a process, every day to yell that they will not programming, in fact, or a little bit.

Here is an orderly list of merged code, a quarter of a blind write, spent 10 minutes or so debugging through, the entire article only an if statement as a recursive exit condition.

#include <stdio.h> #include <stdlib.h> int a[] = {1,3,5,7,8,10,11,12,15,19,21,22,24,25,26};

int b[] = {2,4,5,6,9,16,17,18,27,30,31};
        struct List {struct list *next;
int V;

};

        void merge (struct list *iter, struct list *base) {struct list *last = iter;
        if (!iter) {return;

        ITER = iter->next;
                while (ITER && (!base | | iter->v < BASE-&GT;V)) {last = iter;
        ITER = iter->next;
        } Last->next = base;
Merge (base, ITER);
        int main (int argc, char **argv) {int i = 0, j = 0;
        struct list *al = (struct list*) calloc (in sizeof (*al));
        struct list *BL = (struct list*) calloc (one, sizeof (*BL));
        struct list *itera;

        struct list *iterb;
                        Create 2 lists {for (i = 0; i < i++) {Itera = &al[i]; Itera->v = A[i];
                Itera->next = &al[i+1];

                } itera->next = NULL;
                        for (i = 0; i < i++) {Iterb = &bl[i];
                        Iterb->v = B[i];
                Iterb->next = &bl[i+1];
        } iterb->next = NULL;
        }//Merge 2 lists {merge (Al, BL); }//Print the result {for (; al; al=al->next) {printf ("%d \
                n ", al->v); }
        }
}

Originally wanted to find some meaning for this behavior, because it is too simple (simple does not mean that everyone can write right, I always make indefinite boundary judgment), I have time not to engage in TCP not to do Sdwan, do this.

Mainly is the vacation trip has been wasted, originally wanted to go out, however did not row, had stayed at home for three days.

Ah ha, can teach small ah. You can teach small how to combine two ordered lists into one. When I finish this program, search for someone else on the Internet to write the program, found that I was the simplest, I do not consider what time complexity, in short, can let a six-year-old IQ average child with the shortest time to understand this code is the fundamental purpose, so it is not flashy skills.

The Bamboo rod mans shoes Lightly wins the horse, who is afraid. A life of the rain. However, how to come to the misty rain. What is life.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.