Largest in Array

The source code for program that largest number in an array is given below, copy it in note pad and save it as “.cpp”. Then use suitable compiler to compile it.


/*
 *      
 *      Copyright 2011 techstream.org < techstream.org[at]gmail.com >
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 */
#include
#include
#include


const int size=50;

int front=-1,rear=-1;
int insert(int x, int q[])
{
	if(rear==size-1)
   {
        return -1;
   }
   else if(rear==-1)
   {
   	rear=front=0;
      q[rear]=x;
   }
   else
   {
   	rear++;
      q[rear]=x;
   }
   return 0;
}
void display(int q[])
{
	cout<<"Queue is ->n";
   for(int i=front;i";
      cin>>info;
      temp=insert(info,q);
      if(temp==-1)
      {
	      cout<<"OH ERROR";
   	   getch();
      	exit(0);
      }

      cout<<"nEnter more (Y/N)";
      cin>>ch;
   }
   display(q);

   while(ch=='y'||ch=='Y')
   {
      cout<<"nnPOP an element(Y/N)";
	   cin>>ch;
      if(ch=='y'||ch=='Y')
      {
	     	pop();
		   display(q);
      }
   }
   getch();
}