安舟


私信TA

用户名:dotcpp0603054

访问量:1541

签 名:

等  级
排  名 234
经  验 6013
参赛次数 0
文章发表 21
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

typedef struct Node

{

char a[32];

struct Node *next;

int length;

}Node;

//插入

void Insert(Node *L)

{

int x,y,i=0,j=0;

char b[32];

scanf("%d %s",&x,b);

Node *q=(Node*)malloc(sizeof(Node));

while(i<strlen(b))

q->a[j++]=b[i++];//不要把下标都写成i++了

q->length=j;//为什么用strlen(q->a)会出错

if(L->next==NULL)

{

L->next=q;

q->next=NULL;

}

else

{

Node *p=L;

y=x-1;

while(y--)

p=p->next;

q->next=p->next;

p->next=q;

}

 } 

 //遍历

 void Show(Node *L)

 {

  int i=0;

  Node *p=L->next;

  while(p!=NULL)

  {

  i=0;

while(i<p->length)

  printf("%c",p->a[i++]);

  printf(" ");

  p=p->next;

}

printf("\n");

  } 

  //删除

  void Delete(Node *L)

  {

  Node *p=L->next,*q=L;

  char c[32];

  scanf("%s",&c);

  while(p!=NULL)

  {

  if(strcmp(p->a,c)==0)

  {

  q->next=p->next;

  break;

  }

  p=p->next;

  q=q->next;

  }

   } 

   //查找

 void Search(Node *L)

 {

  char b[32];

  int s=1;

  scanf("%s",b);

  Node *p=L->next;

  while(p!=NULL)

  {

  if(strcmp(p->a,b)==0)

  {

  printf("%d\n",s);

  break;

}

s++;

p=p->next;

}

  } 

int main()

{

Node *L=(Node *)malloc(sizeof(Node));

L->next=NULL;

char a[32];

while(~scanf("%s",a))

{

if(strcmp(a,"insert")==0)

{

Insert(L);

continue;

      }

if(strcmp(a,"show")==0)

{

Show(L);

continue;

   }

if(strcmp(a,"delete")==0)

{

Delete(L);

continue;

    }

if(strcmp(a,"search")==0)

Search(L);

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区