3
Stack Applications Backtracking Backtracking is used in algorithms in which there are steps along some path (state) from some starting point to some goal. Find your way through a maze. Find a path from one point in a graph (roadmap) to another point. Play a game in which there are moves to be made (checkers, chess). In all of these cases, there are choices to be made among a number of options. We need some way to remember these decision points in case we want/need to come back and try the alternative Consider the maze. At a point where a choice is made, we may discover that the choice leads to a dead-end. We want to retrace back to that decision point and then try the other (next) alternative. Again, stacks can be used as part of the solution. Recursion is another, typically more favored, solution, which is actually implemented by a stack.

Application of Stack, Link list , and Queue in Programming

Embed Size (px)

Citation preview

Page 1: Application of Stack, Link list , and Queue in Programming

Stack Applications

Backtracking

Backtracking is used in algorithms in which there are steps along some path (state) from some starting point to some goal. 

Find your way through a maze.  Find a path from one point in a graph (roadmap) to another point.  Play a game in which there are moves to be made (checkers, chess). 

In all of these cases, there are choices to be made among a number of options.  We need some way to remember these decision points in case we want/need to come back and try the alternative

Consider the maze.  At a point where a choice is made, we may discover that the choice leads to a dead-end.  We want to retrace back to that decision point and then try the other (next) alternative.

Again, stacks can be used as part of the solution.  Recursion is another, typically more favored, solution, which is actually implemented by a stack.

Application Of Link List

C Examples on Implementation of Count, Length and Print Operations on a Linked List

The following section contains C Programs which performs operations like count ,finding the length, and printing the elements of the linked list. The programs count the number of occurrences of an element in the linked list using recursion and without using recursion, determines the length of the linked list using recursion and without using recursion and displays the alternate nodes in a linked list using recursion and without using recursion.

Page 2: Application of Stack, Link list , and Queue in Programming

 C Examples on Reverse and Read Operations

This sections has C programs which perform  Reverse and Read operations. Read operation reads the content of the linked list, Remove operation removes the specific contents of a linked list and Reverse operation reverses the contents of the given linked list. The programs in this section   reads a linked list in reverse, removes the duplicate elements from the linked list, reverses a given linked list and reverses the first N elements of a given linked list.

 C Examples on Interchange and Modify Operations

The programs in this section perform Interchange operations. They interchange the two adjacent nodes of a Circular Linked List by touching the key field and without touching the key field. The other program in the section performs the modify Operation. It modifies the given linked list such that all the even numbers appear before the odd numbers in the given linked list. The section has some special programs which solve mathematical problems like Josephus Problem using linked list and a program which performs Infinite Precision Arithmetic.

C Examples dealing with the Operations on the elements of a Linked List

This section contains C Programs which performs operations on the elements of a linked list. These operations include addition of the corresponding elements of 2 linked lists, testing if the two linked lists are same, testing if the given Singly Linked List is a palindrome, finding the number of occurrences of all the elements in a linked list. The section also involves finding the element that is common to both the linked lists and finding the largest element in a Doubly Linked List.