Professional Documents
Culture Documents
Muhammad Sufian
Enrollment Number: 01-134132-130
Class: BS(CS), 4B
Course: Data Structures and Algorithms
sunnykhan.msk@gmail.com
May 1, 2015
My program is doing some sorting functions using doubly link lists. sorting
algorithems includes the following 1- insertion sort 2- selection sort 3- bubble
sort
1- INSERTION SORT: it picks a number and compare that number with
others if coindition become true it swaps that number with the smallest number.
2- SELECTION SORT: it selects the number and compares that number with
the rest and swapswhere the coindition gets true. 3- BUBBLE SORT: it compare
two numbers and swaps them if coindition gets true.
3
1
11
# i n c l u d e <i o s t r e a m >
# i n c l u d e <c o n i o . h>
u s i n g namespace s t d ;
s t r u c t node
{
i n t data ;
node next , p r e v ;
};
class sortings
{
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
node head , t a i l ;
public :
sortings ()
{
head = NULL;
t a i l = NULL;
}
void i n s e r t ( )
{
node temp ;
temp = new node ;
c o u t << ENTER DATA : ;
c i n >> temp>data ;
temp>n e x t = NULL;
temp>p r e v = NULL;
i f ( head == NULL)
{
head = temp ;
t a i l = temp ;
}
else
{
t a i l >n e x t = temp ;
t a i l = temp ;
}
}
void display ( )
{
node temp = head ;
w h i l e ( temp != NULL)
{
c o u t << temp>data << ;
temp = temp>n e x t ;
45
47
49
51
53
55
57
59
61
63
65
67
}
}
void s e l e c t i o n ( )
{
node temp ;
f o r ( node temp1 = head ; temp1 != NULL; temp1 = temp1>n e x t )
{
f o r ( node temp = head ; temp != NULL; temp = temp>n e x t )
{
i f ( temp1>data < temp>data )
{
i n t temp2 ;
temp2 = temp1>data ;
temp1>data = temp>data ;
temp>data = temp2 ;
}
}
}
display () ;
}
v o i d b ub bl e ( )
{
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
} w h i l e ( data != 5 ) ;
getch () ;
137
139