fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct DNode{
  5. int data;
  6. DNode* pPrev, *pNext;
  7. };
  8.  
  9. void delete1K(DNode* &pHead, int k);
  10. void deleteAllKs(DNode* &pHead, int k);
  11.  
  12. //-----------------------------------------------------//
  13.  
  14. void delete1K(DNode* &pHead, int k) {
  15. for(DNode *cur = pHead; cur; cur = cur->pNext) {
  16. if(cur->data == k) {
  17. if(cur->pNext)
  18. cur->pNext->pPrev = cur->pPrev;
  19. if(cur->pPrev)
  20. cur->pPrev->pNext = cur->pNext;
  21. else
  22. pHead = cur->pNext;
  23. delete cur;
  24. break;
  25. }
  26. }
  27. }
  28.  
  29. //-----------------------------------------------------//
  30.  
  31. void deleteAllKs(DNode* &pHead, int k) {
  32. for(DNode* cur = pHead; cur;)
  33. if(cur->data == k) {
  34. if(cur->pNext)
  35. cur->pNext->pPrev = cur->pPrev;
  36. if(cur->pPrev)
  37. cur->pPrev->pNext = cur->pNext;
  38. else pHead = pHead->pNext;
  39. DNode* tmp = cur;
  40. cur = cur->pNext;
  41. delete tmp;
  42. }
  43. else cur = cur->pNext;
  44. }
  45.  
  46. //-----------------------------------------------------//
  47.  
  48. int main() {}
Success #stdin #stdout 0.01s 5456KB
stdin
Standard input is empty
stdout
Standard output is empty