qq_27661225 2015-04-23 12:54 采纳率: 0%
浏览 1588

大一狗遇到了一个问题,请大手帮忙看看!!!!

  1. #include
  2. #include
  3. #include
  4. struct Node
  5. {
  6. int num;
  7. char name[10];
  8. char sex;
  9. int phone_number;
  10. char addr[31];
  11. struct Node *pnext;
  12. struct Node *pfront;
  13. };
  14. struct Node * creat()
  15. {
  16. struct Node *head,*temp,*tail=0;
  17. int numtemp;
  18. printf("请输入编号姓名性别电话号码和住址,编号为0退出:\n");
  19. scanf("%d",&numtemp);
  20. while(numtemp>0)
  21. {
  22. temp=(struct Node *)malloc(sizeof(struct Node));
  23. temp->num=numtemp;
  24. scanf("%s%c%d%s",temp->name,&temp->sex,&temp->phone_number,temp->addr);
  25. if(!head)
  26. {
  27. head=tail=temp;
  28. }
  29. else
  30. {
  31. tail->pnext=temp;
  32. temp->pfront=tail;
  33. tail=temp;
  34. }
  35. printf("请输入编号姓名性别电话号码和住址,编号为0退出\n");
  36. scanf("%d",&numtemp);
  37. }
  38. return head;
  39. }
  40. void getin(struct Node *head)
  41. {
  42. struct Node *p;
  43. struct Node *temp=head;
  44. p=(struct Node *)malloc(sizeof(struct Node));
  45. printf("输入新添加联系人的编号姓名性别电话号码和住址");
  46. scanf("%d%s%c%d%s",&p->num,&p->name,&p->sex,&p->phone_number,&p->addr);
  47. while(temp->pnext!=NULL)
  48. {
  49. if((temp->num)>(p->num))
  50. {
  51. p->pfront=temp->pfront;
  52. temp->pfront->pnext=p;
  53. p->pnext=temp;
  54. temp->pfront=p;
  55. }
  56. else
  57. temp=temp->pnext;
  58. }
  59. if(p->pnext==NULL)
  60. {
  61. temp->pnext=p;
  62. p->pfront=temp;
  63. }
  64. }
  65. void put(struct Node * head)
  66. {
  67. struct Node *temp=head;
  68. while(temp->pnext!=NULL)
  69. {
  70. printf("%d\t%s\t%c\t%d\t%s\t",temp->num,temp->name,temp->sex,temp->phone_number,temp->addr);
  71. temp=temp->pnext;
  72. printf("\n");
  73. }
  74. printf("%d\t%s\t%c\t%d\t%s\t",temp->num,temp->name,temp->sex,temp->phone_number,temp->addr);
  75. }
  76. struct Node * serch(struct Node *head,char *names)
  77. {
  78. while(head!=NULL)
  79. {
  80. if(strcmp(head->name,names)==0)
  81. return head;
  82. else
  83. head=head->pnext;
  84. }
  85. printf("没有找到相关联系人");
  86. return 0;
  87. }
  88. void dele(struct Node *head,char *names)
  89. {
  90. while(head!=NULL)
  91. {
  92. if(strcmp(head->name,names)==0)
  93. {
  94. head->pfront->pnext=head->pnext;
  95. head->pnext->pfront=head->pfront;
  96. free(head);
  97. break;
  98. }
  99. else
  100. head=head->pnext;
  101. }
  102. }
  103. int main()
  104. {
  105. struct Node *head;
  106. int n;
  107. char names[20];
  108. char names2[20];
  109. struct Node *p;
  110. printf("创建通讯录请输入1,插入输入2,删除输入3,输出输入4,查找输入5,退出输入0\n");
  111. scanf("%d",&n);
  112. while(n!=0)
  113. {
  114. switch(n)
  115. {
  116. case 1:
  117. head=creat();
  118. break;
  119. case 2:
  120. getin(head);
  121. break;
  122. case 3:
  123. printf("请输入要删除的联系人姓名\n");
  124. gets(names);
  125. dele(head,names);
  126. break;
  127. case 4:
  128. put(head);
  129. break;
  130. case 5:
  131. printf("请输入要查找联系人的姓名\n");
  132. gets(names2);
  133. p=serch(head,names2);
  134. printf("%d\t%s\t%c\t%d\t%s",p->num,p->name,p->sex,p->phone_number,p->addr);
  135. break;
  136. case 0:
  137. while(head!=NULL)
  138. {
  139. struct Node *p=head;
  140. head=head->pnext;
  141. free(p);
  142. }
  143. return 0;
  144. }
  145. }
  146. return 0;
  147. }
  • 写回答

6条回答 默认 最新

  • devmiao 2015-04-23 12:58
    关注

    代码太长了,直接说你遇到了什么问题吧。

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码