91学习

陪伴你每一天!

输出最火的3个游戏

#include <stdio.h>

#include <stdlib.h>


struct Game{

char cName[20];

int iNumber;

struct Game* pNext;

};

int iCount;

struct Game* Create(){

struct Game* pHead=NULL;

struct Game* pEnd,*pNew;

iCount=0;

pEnd=pNew=(struct Game*)malloc(sizeof(struct Game));

printf("please first enter Name,then Number\n");

scanf("%s",&pNew->cName);

scanf("%d",&pNew->iNumber);

while(pNew->iNumber!=0){

iCount++;

if(iCount==1){

pNew->pNext=pHead;

pEnd=pNew;

pHead=pNew;

}else{

pNew->pNext=NULL;

pEnd->pNext=pNew;

pEnd=pNew;

}

pNew=(struct Game*)malloc(sizeof(struct Game));

scanf("%s",&pNew->cName);

scanf("%d",&pNew->iNumber);

}

free(pNew);

return pHead;

}

void Print(struct Game* pHead){

struct Game* pTemp;

int iIndex=1;

printf("-----the list has %d memebers:----\n",iCount);

printf("\n");

pTemp=pHead;

while(pTemp!=NULL){

printf("the NO%d member is:\n",iIndex);

printf("the name is:%s\n",pTemp->cName);

printf("the number is:%d\n",pTemp->iNumber);

printf("\n");

pTemp=pTemp->pNext;

iIndex++;

}

}

struct Game* Insert(struct Game* pHead){

struct Game* pNew;

printf("-----Insert into a member at first:-----\n");

pNew=(struct Game*)malloc(sizeof(struct Game));

scanf("%s",&pNew->cName);

scanf("%d",&pNew->iNumber);


pNew->pNext=pHead;

pHead=pNew;

iCount++;

return pHead;

}


void Delete(struct Game* pHead,int iIndex){

int i;

struct Game* pTemp;

struct Game* pPre;

pTemp=pHead;

pPre=pTemp;


printf("-----delete NO%d memeber-----\n",iIndex);

for(i=1;i<iIndex;i++){

pPre=pTemp;

pTemp=pTemp->pNext;

}

pPre->pNext=pTemp->pNext;

iCount--;

}


int main(){

struct Game* pHead;

pHead=Create();

pHead=Insert(pHead);

Delete(pHead,2);

Print(pHead);

return 0;

}

加威信18790284560免费送POS机.jpg

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。