Advertisement
DilyaraL

семестровка2

Apr 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5.  
  6. struct node
  7. {
  8. char info;
  9. node * next;
  10. };
  11. void setNull(node * & p)
  12. {
  13. p = NULL;
  14. }
  15. void createElem(node * & p, char y)
  16. {
  17. p = new node;
  18. p->info = y;
  19. p->next = NULL;
  20. }
  21. void addFirst(node * & head1, node * p)//добавление в начало
  22. {
  23. p->next = head1;
  24. head1 = p;
  25. }
  26. void setHead(node * head1, node * & p)
  27. {
  28. p = head1;
  29. }
  30. bool nodeIsNull(node * p)
  31. {
  32. return p == NULL;
  33. }
  34. void showNode(node * p)
  35. {
  36. cout << p->info;
  37. }
  38. void moove(node * & p)
  39. {
  40. p = p->next;
  41. }
  42. void createListFromFile(node * & head1, ifstream & f)
  43. {
  44. node * q;
  45. char x;
  46. head1 = new node;
  47. setNull(head1->next);
  48. node* tail = head1;
  49. while (f.get(x))
  50. {
  51. createElem(q, x);
  52. tail->next = q;
  53. tail = q;
  54. }
  55. q = head1;
  56. moove(head1);
  57. delete q;
  58. }
  59. void showList(node * head)
  60. {
  61. node * q;
  62. setHead(head, q);
  63. while (!nodeIsNull(q))
  64. {
  65. showNode(q);
  66. moove(q);
  67. }
  68. cout << endl;
  69. }
  70.  
  71. void Del(node *& head)
  72. {
  73. node * q,*temp;
  74. bool t;
  75. setHead(head, q);
  76. while (!nodeIsNull(q))
  77. {
  78. if (q->info == ' ')
  79. {
  80. t = false;
  81. temp = q;
  82. moove(q);
  83. while (!nodeIsNull(q)&&q->info != ' ')
  84. {
  85. if (q->info == 'f')
  86. t = true;
  87. moove(q);
  88. }
  89. if (t)
  90. temp->next = q;
  91. }
  92. else
  93. {
  94. t = false;
  95. while (!nodeIsNull(q) && q->info != ' ')
  96. {
  97. if (q->info == 'f')
  98. t = true;
  99. moove(q);
  100. }
  101. if (t)
  102. head = q;
  103. }
  104.  
  105. }
  106. }
  107.  
  108. int main()
  109. {
  110. ifstream f("Text.txt");
  111. node * head1;
  112. createListFromFile(head1, f);
  113. showList(head1);
  114.  
  115. Del(head1);
  116. showList(head1);
  117.  
  118. system("pause");
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement