84 bubbling sorted Text data

Source: Internet
Author: User

Take advantage of all the knowledge you've learned before.
Randomly generate 10 numbers (1-1000), one line at a, and coexist in 1.txt.


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int F_gettimestamp () {
time_t L_now;
Time (&l_now);
return (int) L_now;
}

void f_randomize (int p_v1) {
Srand (P_V1);
}

int F_rand (int p_min, int p_max) {
Return rand ()% (P_max-p_min + 1) + p_min;
}

void Main () {
int l_time = F_gettimestamp ();
F_randomize (L_time);
int l_length = 10; Sets the number of random numbers that are generated.
int *p = (int *) calloc (l_length, sizeof (int));
for (size_t i = 0; i < l_length; i++) {
P[i] = F_rand (1, 1000);
}

FILE * L_fp_write = fopen ("1.txt", "w");
if (l_fp_write! = NULL) {
Char l_out[20] = {0};
for (size_t i = 0; i < l_length; i++) {
sprintf (L_out, "%d\n", P[i]);
Fputs (L_out, l_fp_write);
}
}
Fclose (L_fp_write);
Free (p);
System ("pause");
}

Then read the data in 1.txt, use the bubbling algorithm to sort, and then re-save to 1.txt after sorting.

84 bubbling sorted Text data

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.