同一花色的扑克牌13张。将第一张放入最后,抽取最上面的一张,在将最上面的一张放入最后,以此类推。最后结果是A 2 3 4 5 6 7 8 9 10 j Q k 求原始的牌的顺序
#include <stdio.h>
#include <stdlib.h>
typedef int DATATYPE;
typedef struct node {
DATATYPE data;
struct node *next;
}Linklist;
Linklist *create_empty_linklist( )
{
struct node *head;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
return head;
}
int insert_head_linklist(Linklist *head,DATATYPE data)
{
struct node *temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=data;
temp->next=head->next;
head->next=temp;
return 0;
}
int remov_tail_linklist(Linklist *head)
{
int j=0;
struct node *temp;
struct node *p=head;
while(p->next->next!=NULL)p=p->next;
temp=p->next;
p->next=temp->next;
printf("removnode:%d\n",temp->data);
j=temp->data;
free(temp);
temp=NULL;
return j;
}
int print_linklist(Linklist *head )
{
struct node *p=head->next;
while(p!=NULL)
{
printf("%d",p->data);
p=p->next;
}
printf("\n");
return 0;
}
int main( )
{
int i;
int a[]={13,12,11,10,9,8,7,6,5,4,3,2,1};
Linklist*L=create_empty_linklist( );
for(i=0;i<13;i++)
{
insert_head_linklist(L,a[i]);
insert_head_linklist(L,remov_tail_linklist(L));
}
print_linklist(L);
return 0;
}