求顺序表中值为x的节点个数,要有主函数部分,要求在visual c++下编译运...
答案:1 悬赏:50 手机版
解决时间 2021-03-18 03:18
- 提问者网友:雪舞兮
- 2021-03-17 08:09
求顺序表中值为x的节点个数,要有主函数部分,要求在visual c++下编译运...
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-03-17 09:31
#include "stdio.h"
#include "stdlib.h"
typedef struct _mylist{
int value;
struct _mylist * next;
}MyList;
typedef MyList* pMyList;
int main()
{
int i=0;
pMyList pHead, pTmp;
int count = 0;
int x=8;
pHead = pTmp = (pMyList) malloc(sizeof(MyList));
pTmp->value = 8;
for ( i=0;i<9;i++)
{
pTmp->next = (pMyList) malloc(sizeof(MyList));
pTmp = pTmp->next;
pTmp->value = i;
pTmp->next = NULL;
}
pTmp = pHead;
while (pTmp)
{
if (pTmp->value == x)
{
count++;
}
pTmp = pTmp->next;
}
printf("值为x的节点个数: %d", count);
getchar();
}
#include "stdlib.h"
typedef struct _mylist{
int value;
struct _mylist * next;
}MyList;
typedef MyList* pMyList;
int main()
{
int i=0;
pMyList pHead, pTmp;
int count = 0;
int x=8;
pHead = pTmp = (pMyList) malloc(sizeof(MyList));
pTmp->value = 8;
for ( i=0;i<9;i++)
{
pTmp->next = (pMyList) malloc(sizeof(MyList));
pTmp = pTmp->next;
pTmp->value = i;
pTmp->next = NULL;
}
pTmp = pHead;
while (pTmp)
{
if (pTmp->value == x)
{
count++;
}
pTmp = pTmp->next;
}
printf("值为x的节点个数: %d", count);
getchar();
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯