Things don't have to end where your ex left you...you just have to do 3 things: thinking about what went wrong, fixing what went wrong, and showing your ex that you've fixed what went wrong. Now, that's a really simple way to put it, and it may be a little misleading...so I'll elaborate on each point.
Thinking about what went wrong is NOT just sitting around mourning over your dead relationship and interrogating yourself as to what's the matter with you. Yes, you need to find out what you did wrong, but hopeless whining over a bucket of ice cream isn't your target means of attack. Remember that relationships usually end because one person either wasn't getting what he or she needed out of the relationship, or something his or her partner was doing was driving him/her away.
Both of these can be lethal to even a very close relationship, but sadly they do happen, and it makes sense that they can be showstoppers. I mean, who would stay with a person who was actively driving him or her away? Who would let themselves be stuck in a relationship that just wasn't fulfilling their needs? It's harsh, but true.
You need to analyze your relationship, and figure out which you were doing. Were you pushing your ex away, or were you not providing for your ex's needs? Once you've come to understand what wasn't going right, you can work on fixing it.
When you first set out towards actually fixing the problem, it's important to remember that you can only really do anything about the problems that are your fault. It doesn't matter what you think your ex may have done wrong, it's your job to focus on yourself. Whatever you contributed to the breakup, you have to aim all of your self-improving attention at it. There are going to be sacrifices, that's just part of the process.
Now, nobody said that this will be easy, but let me tell you straight up that it's completely worth it. If you can do this, not only will you have a much higher chance of making it work with your ex but you'll also just feel better about yourself in general.
Once you've done all you can to get yourself in top relationship shape, the time comes to talk to your ex for the first time. Always remember that the first contact is very light and simple. You should be calling or emailing to see how he/she is doing, not to talk about feelings or the failed relationship. It's a sign of consideration, that you care about how he/she's doing. Don't overdo it, or you'll scare your ex off.
Once you've broken the ice again and you're spending time with one another again, let the changes you've made to yourself speak for themselves. If you did a good job on yourself, your ex will notice...and chances are you may become attractive again.
There's no such thing as an easy, foolproof fix for a broken relationship, but this formula is about the closest you'll come by. Remember too that even if your ex just simply isn't into giving it another shot, that's not the end of the world. The changes you've made to yourself will serve to both boost your confidence and make you a more attractive possibility for a lot of other people...and in a world of six billion people, you're bound to find somebody who makes you incredibly happy. Good luck.