fork(2) download
  1. #include <iostream>
  2. #include <unordered_set>
  3. using namespace std;
  4.  
  5. struct Node
  6. {
  7. int data;
  8. Node* next;
  9. };
  10.  
  11. int FindMergeNode_Hash(Node *headA, Node *headB);
  12.  
  13. int main()
  14. {
  15. Node *a = new Node();
  16. Node *b = new Node();
  17. Node *c = new Node();
  18. Node *d = new Node();
  19. Node *e = new Node();
  20. Node *f = new Node();
  21. Node *g = new Node();
  22.  
  23. a->data=1;
  24. a->next=b;
  25.  
  26. b->data=2;
  27. b->next=c;
  28.  
  29. c->data=3;
  30. c->next=d;
  31.  
  32. d->data=4; // Meeting Point
  33. d->next=e;
  34.  
  35. e->data=5;
  36. e->next=f;
  37.  
  38. f->data=6;
  39. f->next=g;
  40.  
  41. g->data=7;
  42. g->next=NULL;
  43.  
  44. Node *A = new Node();
  45. Node *B = new Node();
  46. Node *C = new Node();
  47.  
  48. A->data = 11;
  49. A->next = B;
  50.  
  51. B->data = 12;
  52. B->next = C;
  53.  
  54. C->data = 13;
  55. C->next = d;
  56.  
  57. int ans = FindMergeNode_Hash(A, a);
  58. cout<<"Lists meet at "<<ans<<"\n";
  59. return 0;
  60. }
  61.  
  62. int FindMergeNode_Hash(Node *headA, Node *headB)
  63. {
  64. unordered_set<Node*> h;
  65. while(headA->next)
  66. {
  67. h.insert(&headA);
  68. headA = headA->next;
  69. }
  70. while(headB->next)
  71. {
  72. unordered_set <Node*>::iterator got = h.find (&headB);
  73. if ( got != h.end() )
  74. return headB->data;
  75. }
  76. return -1;
  77. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int FindMergeNode_Hash(Node*, Node*)’:
prog.cpp:67:24: error: no matching function for call to ‘std::unordered_set<Node*>::insert(Node**)’
         h.insert(&headA);
                        ^
In file included from /usr/include/c++/6/unordered_set:48:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/unordered_set.h:412:7: note: candidate: std::pair<typename std::_Hashtable<_Value, _Value, _Alloc, std::__detail::_Identity, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__detail::__is_noexcept_hash<_Tp, _Hash> > >::value, true, true> >::iterator, bool> std::unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(const value_type&) [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; typename std::_Hashtable<_Value, _Value, _Alloc, std::__detail::_Identity, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__detail::__is_noexcept_hash<_Tp, _Hash> > >::value, true, true> >::iterator = std::__detail::_Node_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::value_type = Node*]
       insert(const value_type& __x)
       ^~~~~~
/usr/include/c++/6/bits/unordered_set.h:412:7: note:   no known conversion for argument 1 from ‘Node**’ to ‘Node* const&’
/usr/include/c++/6/bits/unordered_set.h:416:7: note: candidate: std::pair<typename std::_Hashtable<_Value, _Value, _Alloc, std::__detail::_Identity, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__detail::__is_noexcept_hash<_Tp, _Hash> > >::value, true, true> >::iterator, bool> std::unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(std::unordered_set<_Value, _Hash, _Pred, _Alloc>::value_type&&) [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; typename std::_Hashtable<_Value, _Value, _Alloc, std::__detail::_Identity, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__detail::__is_noexcept_hash<_Tp, _Hash> > >::value, true, true> >::iterator = std::__detail::_Node_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::value_type = Node*]
       insert(value_type&& __x)
       ^~~~~~
/usr/include/c++/6/bits/unordered_set.h:416:7: note:   no known conversion for argument 1 from ‘Node**’ to ‘Node*&&’
/usr/include/c++/6/bits/unordered_set.h:441:7: note: candidate: std::unordered_set<_Value, _Hash, _Pred, _Alloc>::iterator std::unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(std::unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator, const value_type&) [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::iterator = std::__detail::_Node_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator = std::__detail::_Node_const_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::value_type = Node*]
       insert(const_iterator __hint, const value_type& __x)
       ^~~~~~
/usr/include/c++/6/bits/unordered_set.h:441:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/6/bits/unordered_set.h:445:7: note: candidate: std::unordered_set<_Value, _Hash, _Pred, _Alloc>::iterator std::unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(std::unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator, std::unordered_set<_Value, _Hash, _Pred, _Alloc>::value_type&&) [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::iterator = std::__detail::_Node_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator = std::__detail::_Node_const_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::value_type = Node*]
       insert(const_iterator __hint, value_type&& __x)
       ^~~~~~
/usr/include/c++/6/bits/unordered_set.h:445:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/6/bits/unordered_set.h:460:2: note: candidate: template<class _InputIterator> void std::unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>]
  insert(_InputIterator __first, _InputIterator __last)
  ^~~~~~
/usr/include/c++/6/bits/unordered_set.h:460:2: note:   template argument deduction/substitution failed:
prog.cpp:67:24: note:   candidate expects 2 arguments, 1 provided
         h.insert(&headA);
                        ^
In file included from /usr/include/c++/6/unordered_set:48:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/unordered_set.h:471:7: note: candidate: void std::unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(std::initializer_list<typename std::_Hashtable<_Value, _Value, _Alloc, std::__detail::_Identity, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__detail::__is_noexcept_hash<_Tp, _Hash> > >::value, true, true> >::value_type>) [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; typename std::_Hashtable<_Value, _Value, _Alloc, std::__detail::_Identity, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__detail::__is_noexcept_hash<_Tp, _Hash> > >::value, true, true> >::value_type = Node*]
       insert(initializer_list<value_type> __l)
       ^~~~~~
/usr/include/c++/6/bits/unordered_set.h:471:7: note:   no known conversion for argument 1 from ‘Node**’ to ‘std::initializer_list<Node*>’
prog.cpp:72:61: error: no matching function for call to ‘std::unordered_set<Node*>::find(Node**)’
         unordered_set <Node*>::iterator got = h.find (&headB);
                                                             ^
In file included from /usr/include/c++/6/unordered_set:48:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/unordered_set.h:585:7: note: candidate: std::unordered_set<_Value, _Hash, _Pred, _Alloc>::iterator std::unordered_set<_Value, _Hash, _Pred, _Alloc>::find(const key_type&) [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::iterator = std::__detail::_Node_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::key_type = Node*]
       find(const key_type& __x)
       ^~~~
/usr/include/c++/6/bits/unordered_set.h:585:7: note:   no known conversion for argument 1 from ‘Node**’ to ‘Node* const&’
/usr/include/c++/6/bits/unordered_set.h:589:7: note: candidate: std::unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator std::unordered_set<_Value, _Hash, _Pred, _Alloc>::find(const key_type&) const [with _Value = Node*; _Hash = std::hash<Node*>; _Pred = std::equal_to<Node*>; _Alloc = std::allocator<Node*>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator = std::__detail::_Node_const_iterator<Node*, true, false>; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::key_type = Node*]
       find(const key_type& __x) const
       ^~~~
/usr/include/c++/6/bits/unordered_set.h:589:7: note:   no known conversion for argument 1 from ‘Node**’ to ‘Node* const&’
stdout
Standard output is empty