c笔试题

同一花色的扑克牌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;

}       


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值