-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabExam2.cpp
More file actions
105 lines (81 loc) · 1.03 KB
/
LabExam2.cpp
File metadata and controls
105 lines (81 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char data;
struct node *next,*prev;
};
struct node *start,*end,*ptr;
int count=0;
void insert(char val)
{
ptr=(struct node*)malloc(sizeof(struct node));
ptr->data=val;
if(start==NULL)
{
start=end=ptr;
ptr->next=NULL;
ptr->prev=NULL;
}
else
{
ptr->next=NULL;
ptr->prev=end;
end->next=ptr;
end=ptr;
}
}
void sort()
{
char a[1000];
ptr=start;
int i=0,j;
char temp;
while(ptr!=NULL)
{
a[i]=ptr->data;
i++;
ptr=ptr->next;
}
for(i=0;i<count-1;i++)
{
for(j=i+1;j<count;j++)
{
if(((int)a[i])<((int)a[j]))
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
start=NULL;
for(i=0;i<count;i++)
insert(a[i]);
}
void display()
{
ptr=start;
while(ptr!=NULL)
{
printf("%c",ptr->data);
ptr=ptr->next;
}
printf("\n");
}
int main()
{
printf("Enter a string \n");
char s[1000];
gets(s);
int i=0;
while(s[i]!='\0')
{
insert(s[i]);count++;
i++;
}
sort();
display();
}