Code:
     if (head1->temperature>=1000 || head2->temperature>=1000)
      k=1;
      p=head2;
Are those two lines supposed to belong to the if, or just the one? (Your indentation needs work.)
Code:
for each element in head1
    for each element in head2
        if head1->something == head2->something
            print it
Now keep in mind that you should be using different pointers for at least h2, so that you can get back to the start each time the inner loop starts again.


Quzah.