Both focus on the theme of moral corruption.
In Lord of the Flies, we see the state of mind of the children begin to change from an organized, civilized society to one of total chaos. Initially, Piggy represents civilization and strives to keep the other children as civilized as possible as he constantly quotes his aunt and uses the conch as a tool to social order. Ralph also represents that of moral civility as he attempts to lead the group without violence and remains reasonable throughout the adventures on the island.
Jack, however, is a foil character to Ralph and represents the absolute worst of human nature. His power struggle and goals of complete control of the island corrupt the other boys and eventually leads to the death of Piggy and the attempted murder of Ralph. It is Jack and his ability to frenzy his mob of followers that leads to the moral corruption of all the surviving boys except for Ralph.
In Shakespeare's Hamlet, moral corruption is portrayed through the attempts to gain control of Denmark. After the passing of King Hamlet, Prince Hamlet begins acting strangely around Ophelia, a woman whom Prince Hamlet is swooning over. Confused by his strange actions, Ophelia is convinced to allow Claudius and Polonius to listen in on a converstation between Ophelia and Prince Hamlet. After Prince Hamlet watches the re-enactment of his own father's death, he is convinced that Claudius murdered his father, King Hamlet, by his reaction to the play.
With madness continuing to rule Prince Hamlet, he accidentally kills Polonius behind an arras thinking it is Claudius hiding yet shows no remorse for his actions. The audience begins to see Prince Hamlet's mind begin to focus more and more on murder when he reacts to the men going to war in Poland and declares "O, from this time forth,/My thoughts be bloody, or be nothing worth!" Thus the plots for murder continue to spiral out of control until the end when Laeretes, Claudius, Gertude, and Prince Hamlet himself.