#include
#include
struct node
{
int data;
node* next;
}
node* create(int Array[])
{
node p,*pre,*head;
head = new node;
head->next=NULL;
pre=head;
for(int i=0;i
p=new node;
p->data=Array[i];
p->next=NULL;
pre->next=p;
pre=p;
}
return head;
}
int search(node head,int x)
{
int cout=0
node* p=head->next;
while(p!=NULL){
if(p->data==x) count++;
p=p->next;
}
return count;
}
void insert(node* head,int pos,int x)
{
node* p=head;
for(int i=0;i
p=p->next;
}
node* q=new node;
q->data=x;
q->next=p->next;
p->next=q;
}
void del(node* head,int x)
{
node* pre =head;
while(p!=NULL){
if(p->data==x){
pre->next=p->next;
delete(p);
p=pre->next;
}else{
pre=p;
p=p->next;
}
}
}
int main()
{
int Array[9]={9,8,7,6,5,4,3,2,1};
node* L=create(Array);
node* q=L;
L=L->next;
printf("输出所建链表的元素:");
while(L!=NULL){
printf("%d",L->data);
L=L->next;
}
printf("\n查找元素为5的个数:%d\n",search(q,5));
del(q,5);
printf("删除元素为5的结点之后的链表;");
L=q->next;
while(L!=NULL){
printf("%d",L->data);
L=L->next;
}
insert(q,8,10);
printf("\n在第8个位置插入元素为10的结点之后的链表;");
L=q->next;
while(L!=NULL){
printf("%d",L->data);
L=L->next;
}
return 0;
}
这是我在百度上找的,但是总是运行不了,来求救大神们出手了。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
0条回答 默认 最新
悬赏问题
- ¥15 SQL Server下载
- ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
- ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
- ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
- ¥15 python爬取bilibili校园招聘网站
- ¥30 求解达问题(有红包)
- ¥15 请解包一个pak文件
- ¥15 不同系统编译兼容问题
- ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
- ¥30 数字电源对DSP芯片的具体要求