Quick drain of c language library functions

Before all handwritten quick drain but after all write too much time is quickly lined up with a wave of his own soon lined up to say with a good package stl feel something either before the truth can not help but really handy I went back to remember when using python to write complex data structures simply do not play too simple save a lot of words but also to ensure the correct
ordering of the C language is fast qsort row
first and then address a few elements and the size of each element and then a comparator
cmp important to return to a positive number greater than 0 is equal to it a negative number is less than your own
back qsort try not to support sorting stl c ++ inside with c ++ it is not my own sort also OK

#include<cstdio>
#include<cstdlib>
using namespace std;
int cmp(const void*a,const void *b)
{
	if(*(int*)a == 11)
	{
		return 1;
	}
	if(*(int*)a == 100)
	{
		return -1;
	}
	return 0;
}
int main(void) 
{
	int n;
	scanf("%d",&n);
	int a[n],i;
	for(i = 0;i < n;i++)
	{
		scanf("%d",a+i);
	}   
	qsort(a,n,sizeof(int),cmp);
	
	for(i= 0;i < n;i++)
	{
		printf("%d ",a[i]);
	}
	puts("");
	main();
	return 0;
}

Just tried it found that it seems not forget qsort in C ++ or its own sort it
hey ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I really want to be of C ++ gradually begin
from the beginning to the present entirely in C C half half of the C ++ I am very melancholy feeling each write half of this semi-C C ++ code seems to be carrying a good feel guilty C and C ++ affair

enum 算了不写 C++ 的快排了
Published 37 original articles · won praise 0 · Views 337

Guess you like

Origin blog.csdn.net/weixin_43191153/article/details/104543117