It's difficult to say whether All the King's Men ends happily or tragically. The novel starts ending with the suicide of Judge Irwin. It continues ending with the deaths of Adam Stanton, and then Willie Stark, followed by the death of Tom Stark.
But the novel doesn't actually end on a tragic note. We wouldn't exactly call this work a comedy either. Comedies typically end in some sort of reunion, often marriage, and present a hopeful order that contrasts with the hopeless chaos of its beginnings. William Shakespeare's Twelfth Night of A Midsummer Night's Dream is a classic example of such a comedy.
All the King's Men has a double layered ending, this first layer being tragedy, and the second layer being "comedy" in the Shakespearean sense.
First, the Judge, then Adam, then Willie, and then Tom die. But, as a result of the Judge's tragedy, Jack learns that his real father is Judge Irwin, and that his mother loved Judge Irwin. Previously, Jack didn't think that she loved anyone, so this news of the affair between his mother and the Judge is hopeful. Knowledge of his past gives Jack the power to deal with his family life and his love for Anne. Jack's new outlook also allows him to love, in some way or other, Ellis Burden, whom he brings to live with him.
The ending seems to argue that tragedy doesn't have to be the end of the story. We have to look beyond the tragedy and into the possible comedy (or hope) waiting in the distance. As such, All the King's Men can be seen as an optimistic book.
Perhaps the novel's optimism is summed up in these words, "But I still had the money, and so I am spending it to live on while I write the book I began years ago, the life of Cass Mastern, whom once I could not understand, but whom, perhaps, I may come to understand" (10.450). This is where the themes of "Education" and "Memory and the Past" collide. Through continued education, and continued exploration of the past, a more positive future can be imagined.
But, for all its optimism, the final lines of the novel make clear that realization of the optimism won't be easy. Jack tells us that when he and Anne leave Judge Irwin's (now Jack's) house in Burden's Landing, they will "go into the convulsions of the world, out of history into history and the awful responsibility of Time" (10.453). This is a little puzzling, but among other things, Jack seems to be saying that with knowledge of history and the past comes a great responsibility – the responsibility to try to make better history in a hurt world, while steal dealing with the repercussions of the past.