ykhyh 2020-03-31 02:58
浏览 77

这是我在百度上找的,但是总是运行不了,来求救大神们出手了。

#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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题