Formation of carbon clusters in deflagration and detonation waves in gas mixtures