1: #include <stdio.h>
2: #include <string.h>
3: void char_sorting_ptr(char *str,int sz)
4: {
5: char temp,*p = str,*c = str;
6: int i = 0,j=0;
7: while( i < sz)
8: {
9: for(j=0,p=str;j < sz-1;j++)
10: {
11: if ( *p > *(p+1))
12: {
13: temp = *(p+1);
14: *(p+1) = *p;
15: *p = temp;
16: }
17: p++;
18: }
19: i++;
20: }
21: }
22: void char_sorting(char *str,int sz)
23: {
24: char temp;
25: int i = 0,j=0;
26: while( i<sz)
27: {
28: for(j=0;j<sz-1;j++)
29: {
30: if ( str[j] > str[j+1])
31: {
32: temp = str[j];
33: str[j] = str[j+1];
34: str[j+1] = temp;
35: }
36: }
37: i++;
38: }
39: }
40: main()
41: {
42: char str[100] = "mynameisjohn";
43: char_sorting_ptr(str,strlen(str));
44: printf("Sorted String : %s\n",str);
45: }
RTOS, Linux Kernel internal, OS-Programming C & Data Structures, Debugging, Optimizations, Makefiles and Wireless Technologies (Wi-Fi ,LTE and LTE-Advanced )
Search This Blog
Wednesday, October 28, 2015
Sort all characters in a given string
Labels:
C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment