Introduction to Algorithms Learning Notes-(1)

Source: Internet
Author: User

An ACM If the course, taking advantage of the ACM off-season, began to learn the introduction of the algorithm, after a year of ACM learning, gradually discovered, learn something, in-depth is the king, before learning an algorithm, always read the beginning to do the problem, until later found a lot of topics, will algorithm, but do not know is using this algorithm, This is the result of the algorithm understanding is not in place, starting from today, set goals:

1. In-depth system learning algorithms,

2. Learn to write pseudo-code on paper, each chapter of the code to write on the paper first,

3. Each section of the learning notes and algorithms are written on the blog.

On the blog to record their own study notes, easy to review later. Welcome to the great gods passing the wrong place.

Now, first write the first algorithm on the book, insert sort.

Algorithm idea: For an array a[n], the

Insertion_sort#include <iostream>using namespace Std;void insertion_sort (int* A, int n) {for    (int j = 1; J < ; N J + +)    {        int key = A[j];        int i = j-1;        Insert A[j] into the sorted sequence a[0..j-1].        while (i >= 0 && a[i] > key)        {            a[i+1] = a[i];            i--;        }        A[I+1] = key;    }} void print (int* A, int n) {for    (int i = 0; i < n; i++) {        cout << a[i] << "";    }    cout << Endl;} int main () {    int a[10] = {43,2,53,1,8,29,52,4,8,10};        cout << "before sorted:";    Print (A, ten);        Insertion_sort (A, ten);        cout << "after sorted:";    Print (A, ten);        return 0;}


Introduction to Algorithms Learning Notes-(1)

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.