#include?
"
stdio.h
"
#include?
"
stdlib.h
"
typedef?
struct
{
?
int
?number;
?
int
?dicper;
}
ElemType;
typedef?
struct
?node

{
?ElemType?data;
?
struct
?node?
*
next;
}
Node,
*
LinkList;
void
?Initiatte(LinkList?
&
L)

{
?
if
((L
=
(LinkList)malloc(
sizeof
(Node)))
==
NULL)exit(
1
);
?L
->
next
=
L;
}
int
?Insert(LinkList?
&
L,
int
?i,ElemType?x)

{
?LinkList?q,p;
?p
=
L
->
next;
?
int
?j
=
1
;
?
while
(p
!=
L?
&&
?j
<
i
-
1
)

?
{
??p
=
p
->
next;
??j
++
;
?}
?
if
(j
!=
i
-
1
?
&&
?i
!=
1
)

?
{
??printf(
"
插入位置參數錯!
"
);
??
return
?
0
;
?}
?q
=
(LinkList)malloc(
sizeof
(Node));
?
if
(
!
q)exit(
1
);
?q
->
data
=
x;
?q
->
next
=
p
->
next;
?p
->
next
=
q;
?
return
?
1
;
}
int
?IsNotEmpty(LinkList?L)

{
?
if
(L
->
next
==
L)
return
?
0
;
?
else
?
return
?
1
;
}
int
?Delete(LinkList?
&
p)

{
?LinkList?q;
?q
=
p
->
next;
?p
->
next
=
p
->
next
->
next;
?free(q);
?
return
?
1
;
}
void
?output(LinkList?
&
L,
int
?m)

{
?LinkList?pre,q;
?pre
=
L;
q
=
L
->
next;
?
while
(IsNotEmpty(L)
==
1
)

?
{
??
for
(
int
?i
=
1
;i
<
m;i
++
)

??
{
???pre;
???q
=
q
->
next;
???
if
(q
==
L)

???
{
????pre
=
q;
???q
=
q
->
next;
???}
??}
printf(
"
%d**
"
,q
->
data.number);
?m
=
q
->
data.dicper;
?q
=
q
->
next;
?
if
(q
==
L)q
=
q
->
next;
?Delete(pre);
?}
}
int
?main()

{
?
int
?n;
?printf(
"
請輸入人數的值:\n
"
);
?scanf(
"
%d
"
,
&
n);
?ElemType?
*
P;
?LinkList?L;
?Initiatte(L);
?
int
?i,m;
P?
=
?
new
?ElemType?[n];
?
for
(?i
=
0
;i
<
n;i
++
)

?
{
?P[i].number
=
i
+
1
;
??printf(
"
第%d個人輸入密碼
"
,i
+
1
);
??printf(
"
\n
"
);
??scanf(
"
%d
"
,
&
P[i].dicper);
?}
??
for
(i
=
1
;i
<=
n;i
++
)
??Insert(L,i,P[i
-
1
]);
?printf(
"
對m的數值進行初始化:
"
);
?scanf(
"
%d
"
,
&
m);
?printf(
"
結果輸出:
"
);
?output(L,m);
?delete?[]?P;
?printf(
"
\n
"
);
?
return
?
0
;
}
12
posted on 2006-12-18 22:53
華劍緣 閱讀(251)
評論(0) 編輯 收藏 引用