Basicity in heterocyclic compounds is influenced by electron density and resonance effects.
Piperidine, being a saturated six-membered ring, has the highest basicity due to the availability of its nitrogen lone pair.
Morpholine, containing an oxygen atom, has slightly reduced basicity due to inductive effects.
Pyrimidine has delocalized nitrogen lone pairs, making it less basic than piperidine or morpholine.
Pyrrole has the lowest basicity as its nitrogen lone pair is involved in aromatic conjugation, reducing its ability to donate protons.