Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
Untitled
SUBMITTED BY:
Guest
DATE:
Nov. 26, 2014, 12:48 p.m.
FORMAT:
C++
SIZE:
1.1 kB
Raw
Download
Tweet
HITS:
1358
Go to comments
Report
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
typedef
struct
numType
{
int
num
;
struct
numType
*
next
;
}
node
;
void
main
()
{
//create the list
node
*
head
,
*
pos
;
//nlist = head
int
done
=
1
;
int
temp
;
node
*
p
,
*
q
;
head
=
(
node
*
)
malloc
(
sizeof
(
node
));
head
->
num
=
2
;
pos
=
(
node
*
)
malloc
(
sizeof
(
node
));
head
->
next
=
pos
;
pos
->
num
=
1
;
pos
->
next
=
(
node
*
)
malloc
(
sizeof
(
node
));
pos
->
next
->
num
=
4
;
pos
=
pos
->
next
;
pos
->
next
=
(
node
*
)
malloc
(
sizeof
(
node
));
pos
->
next
->
num
=
3
;
pos
->
next
->
next
=
head
;
head
=
pos
->
next
;
//do the question
do
{
p
=
head
->
next
;
done
=
1
;
while
(
/*1*/
)
{
q
=
p
->
next
;
if
(
p
->
num
>
q
->
num
)
{
temp
=
p
->
num
;
p
->
num
=
q
->
num
;
q
->
num
=
temp
;
done
=
0
;
}
p
=
p
->
next
;
}
}
while
(
/*2*/
);
//print list
pos
=
head
;
printf
(
"%d "
,
pos
->
num
);
pos
=
pos
->
next
;
while
(
pos
!=
head
)
{
printf
(
"%d "
,
pos
->
num
);
pos
=
pos
->
next
;
}
getch
();
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus