Sunday, July 18, 2010

Programs of PUSH & POP functions in C

Function PUSH

        void push ( struct stack *p , int n)
              {
                      if ( p -> tos == MAX-1)
                            {
                                printf( "stack overflow");
                                return;
                             }
                        p -> arr[ ++ p -> tos ] = x;
               }
            


Function POP   :-
        


int pop ( struct stack *p)
             {
                  int n ;
                  if ( p -> tos == -1)
                      {
                         printf( " stack under flow");
                          return -1 ;
                       }
                    n= p-> arr [ p-> tos --] ;
                    return (n);

               }



So friends  we have done with stack implementation  in C.
In the next post we will discuss about various uses of stacks.

2 comments:

  1. Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort.

    a) Consider the following values sorted in an array. Sort it in ascending order using Bubble sort technique showing all the iterations:
    15, 43, 5, 18, 27, 3, 10
    b) Also write a C function to sort one dimensional integer array in ascending order using Bubble Sort technique.



    please if the Question is answer you can contact me via this e mail ansu2bc@yahoo.co.uk

    ReplyDelete
  2. a) Determine with the help of an example whether the initial order of elements is
    preserved in the case of bubble sort.
    b) Write a “c” function to sort a list of integers using insertion sort technique where
    the list is represented through links using pointers.

    c) If “E” and “I” denote the external and internal path lengths of a binary tree having “n” internal nodes then the following identity holds E = I + 2*n. Prove it.

    ReplyDelete