NOB_List01
Home ] Up ]

 

//Date:   2003.09.05
//File:   NOB_List01.cpp
//Author: AOU

#include <iostream.h>
#include <stdlib.h>

/*
maintain an ordered list of integeres
*/

const int MAX_SIZE = 100;


void display(int a[], int n);
void initialize(int a[], int n);
bool insert(int a[], int &n, int x);


void main(void)
  {
  int values[MAX_SIZE];
  initialize(values, MAX_SIZE);

  int n = 0;
  display(values, n);
  
  bool result = insert(values, n, 55);
  cout << result << endl;
  display(values, n);
  }


/*
insert x in a[]
if n = 0 then 
if n = MAX_SIZE 
*/
bool insert(int a[], int &n, int x)
  {
  if (0 == n)
      {
      a[n] = x;
      n++;
      cout << "from insert\n";
      display(a, n);

      return true;
      };

  if (MAX_SIZE == n)
      return false;

  return false;

  }


void initialize(int a[], int n)
  {
  for (int i=0; i<=n-1; i++)
    a[i] = 0;
  }


void display(int a[], int n)
  {
  cout << "a[" << n << "]: ";
  for (int i=0; i<=n-1; i++)
    cout << a[i] << ' ';

  cout << endl;
  }