Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source demo lang Array_S.C
Document Actions

Array_S.C

by Michael L Powell last modified 2007-01-26 03:20

Click here to get the file

Size 1.4 kB - File type text/plain

File contents

/*ident	"@(#)cls4:demo/lang/Array_S.C	1.1" */
/*#########################################################################
#                       Copyright (c) 1991 AT&T
#                         All Rights Reserved   
#
#                THIS IS PROPRIETARY SOURCE CODE OF AT&T
#       
#                     This code has been published in
#                         C++ Primer, 2nd Edition 
#			    by Stanley Lippman
#                    Addison_Wesley Publishing Company
#
#########################################################################*/
#include "Array_S.h"
#include "Array.C"

template <class Type>
Array_Sort<Type>::
Array_Sort(const Array_Sort<Type> &as)
    : Array<Type>( as )
{ 
    // as.check_bit() does not work!
    if ( as.is_dirty() )
	 sort( 0, size-1 );
    clear_bit();
}  

template <class Type>
Array_Sort<Type>::
Array_Sort(int sz)
        : Array<Type>( sz )
	{ clear_bit(); }

template <class Type> void
Array_Sort<Type>::grow()
{ 
    Array<Type>::grow();
    sort( 0, size-1 );
    clear_bit();
}  

template <class Type>
int Array_Sort<Type>::find(Type val) 
{ 
     int low = 0;
     int high = size-1;
     check_bit();

     while ( low <= high )
     { 
          int mid = (low + high)/2;
          if (val == ia[mid])
               return mid;
          if (val < ia[mid])
               high = mid-1;
          else low = mid+1;
      }   

      return not_found;
}  
« May 2024 »
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: