Advertisement
punidota

Untitled

Mar 23rd, 2016
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdafx.h"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. typedef char newtp;
  8. struct node
  9. {
  10. newtp data;
  11. node* next;
  12. node* pred;
  13. };
  14.  
  15. class linklist
  16. {
  17. private:
  18. node* first;
  19. public:
  20. linklist() { first = NULL; }
  21.  
  22. void push(newtp d, int pos);
  23. int pop(int pos);
  24. void clean();
  25. void view();
  26. };
  27.  
  28. void linklist::push(newtp d, int pos)
  29. {
  30.  
  31. node* newnode = new node;
  32. newnode->data = d;
  33. if (first == NULL)
  34. {
  35. newnode->next = newnode;
  36. newnode->pred = newnode;
  37. first = newnode;
  38. }
  39. else
  40. {
  41. node* temp = first;
  42. for (int i = pos; i > 1; i--, temp = temp->next);
  43. temp->pred->next = newnode;
  44. newnode->pred = temp->pred;
  45. newnode->next = temp;
  46. temp->pred = newnode;
  47. }
  48. }
  49.  
  50. int linklist::pop(int pos)
  51. {
  52. if (first == NULL) return 0;
  53. int val;
  54. if (first == first->next)
  55. {
  56. val = first->data;
  57. delete first;
  58. first = NULL;
  59. }
  60. else
  61. {
  62. node* temp = first;
  63. for (int i = pos; i > 1; i--, temp = temp->next);
  64. if (temp == first) first = temp->next;
  65. temp->pred->next = temp->next;
  66. temp->next->pred = temp->pred;
  67. val = temp->data;
  68. delete temp;
  69. }
  70. return val;
  71. }
  72.  
  73. void linklist::clean()
  74. {
  75. if (first == NULL) return;
  76. for (node* newnode = first->next; newnode != first; newnode = newnode->next) delete newnode;
  77. delete first;
  78. first = NULL;
  79. }
  80.  
  81. void linklist::view()
  82. {
  83. if (first == NULL) return;
  84. node* newnode = first;
  85. do
  86. {
  87. cout << newnode->data;
  88. newnode = newnode->next;
  89. } while (newnode != first);
  90. }
  91. int main()
  92. {
  93. setlocale(0,"");
  94. linklist li;
  95. char str[] = "dedededed";
  96. char b[255];
  97. char* pch = strtok(str, " ");
  98. while (pch != NULL)
  99. {
  100. char _ch = pch[0];
  101.  
  102. for (int i = 1; i < strlen(pch); ++i)
  103. {
  104. if (pch[i] == _ch)
  105. {
  106. pch[i] = 'G';
  107. }
  108. }
  109. pch = strtok(NULL, " ");
  110. }
  111.  
  112. for (int i = 0; i < strlen(str); i++)
  113. {
  114. b[i] = *(str+i);
  115. }
  116. for (int i = 0; i < strlen(str); i++)
  117. {
  118. if (b[i] != 'G'){
  119. li.push(b[i], i+1);
  120. }
  121. }
  122.  
  123.  
  124.  
  125. li.view();
  126.  
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement