Just to add to the otherwise excellent answer by Triveth. He still leaves the origin of elliptical galaxies unexplained, i.e. how todo the stars attain the spheroidal shape? After all, most stars form from gas and gas tends to stettlesettle into discs, so why are the stars in elliptical galaxies in a spheroidal distribution but in spiral galaxies in a disc-like distribution?
The standard wisdom is that ellipticalselliptical galaxies have formed form the merger of two or several smaller spiral galaxies. In such mergers, the collisionlesscollision-less nature of the stars means that they will not stay in a disc. Rather energy form the orbit of the progenitor galaxies is transferred into internal energy (which cannot be radiated away as with gas discs), evolving the stellar distributions away from their near-minimal energy state (at given angular momentum), i.e. away from a disc. Additionally, the interaction between the two galaxies re-distributes the individual stellar orbital angular momenta and their orientations, so that they are no longer correleated (as in a disc).
The gas undergoes a completely differntdifferent fate during a merger. It collides and shocks, then cools and forms stars or is funneled onto the central super-massive black holes, where it may turn on a quasar. Energy and momentum feedback from both the quasar and the supernovae resulting from new born massive stars are well capabalecapabable to drive out all remaining gas and leave the galaxy gas poor. Some elliptical galaxies still have a small gas disc and there are also intermediate, so-called S0, galaxies with a clear disc and also a substantial spheroidal component.