当前位置:   article > 正文

数据结构 链表 通讯录_建立某班学生的通讯录,要求用链表存储。

建立某班学生的通讯录,要求用链表存储。
  1. #include "stdafx.h"
  2. #include "windows.h"
  3. #include "iostream"
  4. using namespace std;
  5. typedef struct Pnode
  6. {
  7. char Pname[21];
  8. char Pphone[12];
  9. char Psex[5];
  10. char Padd[21];
  11. Pnode *pNext;
  12. }node,*Node;
  13. int main(int argc,char *argv)
  14. {
  15. void Init_(Node S);
  16. void Delete_(Node S);
  17. void EnList_(Node S);
  18. void OutList_(Node S);
  19. void InsertList_(Node S);
  20. int e;
  21. Node S=(Node)malloc(sizeof(node));
  22. MessageBox(NULL,TEXT("1:Input 2:Reading 3:Delete 4:Insert 5:Help"),
  23. TEXT("Prompt"),MB_OK|MB_ICONQUESTION);
  24. Init_(S);
  25. scanf("%d",&e);
  26. while(1)
  27. {
  28. if(e==1)
  29. {
  30. EnList_(S);scanf("%d",&e);system("cls");
  31. }
  32. else if(e==2)
  33. {
  34. OutList_(S);scanf("%d",&e);system("cls");
  35. }
  36. else if(e==3)
  37. {
  38. Delete_(S);scanf("%d",&e);system("cls");
  39. }
  40. else if(e==4)
  41. {
  42. InsertList_(S);scanf("%d",&e);system("cls");
  43. }
  44. else if(e==5)
  45. {
  46. MessageBox(NULL,TEXT("1:Input 2:Reading 3:Delete 4:Insert 5:Help"),
  47. TEXT("Prompt"),MB_OK|MB_ICONQUESTION);
  48. scanf("%d",&e);system("cls");
  49. }
  50. }
  51. return 0;
  52. }
  53. void Init_(Node S)
  54. {
  55. S->pNext=NULL;
  56. }
  57. void EnList_(Node S)
  58. {
  59. char c;
  60. Node q=S;
  61. while(1)
  62. {
  63. Node p=(Node)malloc(sizeof(node));
  64. puts("Name:");
  65. scanf("%s",&p->Pname);
  66. puts("Phone:");
  67. scanf("%s",&p->Pphone);
  68. puts("Sex:");
  69. scanf("%s",&p->Psex);
  70. puts("Address:");
  71. scanf("%s",&p->Padd);
  72. p->pNext=NULL;
  73. p->pNext=q->pNext;
  74. q->pNext=p;
  75. puts("Next?(Y/N):");
  76. getchar();
  77. c=getchar();
  78. if(c=='y')system("cls");
  79. else
  80. {
  81. system("cls");
  82. break;
  83. }
  84. }
  85. }
  86. void OutList_(Node S)
  87. {
  88. Node p=S->pNext;
  89. puts("Name Phone Sex Address");
  90. while(p)
  91. {
  92. printf("%s %s %s %s\n",p->Pname,p->Pphone,p->Psex,p->Padd);
  93. p=p->pNext;
  94. }
  95. }
  96. void InsertList_(Node S)
  97. {
  98. Node p=S;
  99. Node q=(Node)malloc(sizeof(node));
  100. puts("You want insert information");
  101. puts("Name:");
  102. scanf("%s",&q->Pname);
  103. puts("Phone:");
  104. scanf("%s",&q->Pphone);
  105. puts("Sex:");
  106. scanf("%s",&q->Psex);
  107. puts("Address:");
  108. scanf("%s",&q->Padd);
  109. q->pNext=NULL;
  110. while(p->pNext)
  111. p=p->pNext;
  112. q->pNext=p->pNext;
  113. p->pNext=q;
  114. MessageBox(NULL,TEXT("Success!"),TEXT("Debug"),MB_OK|MB_ICONASTERISK);
  115. }
  116. void Delete_(Node S)
  117. {
  118. char ch[12];
  119. Node p=S;
  120. Node q;
  121. puts("You want delete name:");
  122. getchar();
  123. gets(ch);
  124. while(p->pNext)
  125. {
  126. if(strcmp(p->pNext->Pname,ch)==0)
  127. {
  128. q=p->pNext;
  129. p->pNext=q->pNext;
  130. MessageBox(NULL,TEXT("Success!"),TEXT("Debug"),MB_OK|MB_ICONASTERISK);
  131. break;
  132. }
  133. p=p->pNext;
  134. }
  135. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/559407
推荐阅读
相关标签
  

闽ICP备14008679号