Sort a set of strings using bubble sort

Source: Internet
Author: User

The bubble sort of the string and the whole type bubble sort and the principle is the same, here does not have the bubble sort to do the detailed introduction, gives the source code directly!

#include <stdio.h> #include <stdlib.h> #define N 10int Main () {char *arr[n] = {"Pas", "pase", "abced", "asdf", "  Acdef "," Ertugbs "," Jhgsds "," KSJDJFH "," skjsh "," SMJDJG "};int i = 0;int j = 0;int size = sizeof (arr)/sizeof (arr[0]); for (i = 0; i < size-1;  i++) {for (j = 0; J < Size-1-i; J + +) {if (strcmp (arr[j],arr[j+1]) >0) {char *tmp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = tmp;}}} for (i = 0; i < size; i++) {printf ("%s", Arr[i]);} printf ("\ n"); system ("pause"); return 0;}

In the above program I have defined the size of the pointer array, you can use it without definition, the direct initialization is good. Because of my learning experience and other reasons, the program must have a lot of loopholes, welcome to the great God of my code to write criticism!

This article is from the "Sharing Progress" blog, be sure to keep this source http://xmwen1.blog.51cto.com/10730069/1712521

Sort a set of strings using bubble sort

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.