📄 3.c
字号:
#include <stdio.h>
#include<malloc.h>
typedef struct node{
int Elem;
struct node *next;
}Lnode;
void main()
{
int i,num,times=0;
Lnode *head,*p,*tail;
head =(Lnode*) malloc(sizeof (Lnode));
head->Elem=0;
head->next=NULL;
for (i=0;i<=9 ;i++ )
{
p =(Lnode*) malloc(sizeof (Lnode));
printf("Input the Elem:");
scanf("%d",&p->Elem);
p->next=NULL;
//printf("%d",p->Elem);
if (head->next==NULL)
{
head->next = p;
tail=p;
}
else
{tail->next=p;tail=p;}
}
printf("Input the searching integer:");
scanf("%d",&num);
p=head->next;
//while(p!=NULL){printf("%d ",p->Elem);p=p->next;}
while(p!=NULL)
{if (p->Elem==num)
{
printf("\nThe compare times is %d:",times);
return;
}
else {p=p->next;times++;}
}
if (p==NULL)
{
printf("\nThe Elem is not in!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -