Exemple #1
0
bool BinaryTree<T>::isOrdered(const Node * sub_root) const
{
	// base case:
	if( sub_root == NULL )
	{
		return true;
	}
	// recursive case:
	else
	{
		if( sub_root->left != NULL )
		{
			Node *temp = find_right_most(sub_root);
			if( temp->elem > sub_root->elem )
			{
				return false;
			}
		}
		if( sub_root->right != NULL )
		{
			Node *temp = find_left_most(sub_root);
			if( temp->elem < sub_root->elem )
			{
				return false;
			}
		}
		return isOrdered(sub_root->left)&&isOrdered(sub_root->right);
	}
}
int main() {
    int v1[10] = {37, 5, 4, 8, 12, -10, 23, -20, 30, 35};
    int v2[10] = {-1, 0, 2, 3, 4, 7, 14, 28, 29, 50};
    std::cout << summation(6) << std::endl;
    std::cout << min(v1, 9) << std::endl;
    std::cout << sum(v1, 9) << std::endl;
    std::cout << isOrdered(v1, 9) << std::endl;
    std::cout << isOrdered(v2, 9) << std::endl;
    return 42;
}
Exemple #3
0
bool BinaryTree<T>::isOrdered(Node * subRoot) const
{
	if(subRoot==NULL) return true;
	
	if      ( (maximum(subRoot->right)) < (subRoot->elem) ) return false;
	if ( (minimum(subRoot->left))  > (subRoot->elem) ) return false;


	return ( isOrdered(subRoot->left) && isOrdered(subRoot->right) );
	
}
bool BinaryTree<T>::isOrdered(const Node* subRoot) const 
{	
	if (subRoot == NULL) return true;

	if (subRoot->left !=NULL && (subRoot->left->elem > subRoot->elem)) return false;

	if (subRoot->right !=NULL && (subRoot->right->elem < subRoot->elem)) return false;

	if (!isOrdered(subRoot->right) && !isOrdered(subRoot->left)) return false;

	return true;
	/*queue<T> Q;
	if( subRoot != NULL){
	isOrdered(subRoot->left);
	T c = subRoot->elem;
	Q.push(c);
	isOrdered(subRoot->right);
	}
	return Q;*/
}
bool BinaryTree<T>::isOrdered() const
{	/*queue<T> q;
	q = isOrdered(root);
	while(!q.empty()){
		T a = q.front();
		q.pop();
		T b = q.front();
		if(a>=b) return false;
		if(q.size() ==1) return true;
	}
	return true;*/
	return isOrdered(root);
}
bool BinaryTree<T>::isOrdered(Node * subRoot, Node * &temp) const
{
	if(subRoot == NULL)
		return true;

		
    if(isOrdered(subRoot->left, temp) == false)
    	return false;
    	
    if(temp == NULL)
    	temp = subRoot;
    
	else if(subRoot->elem <= temp->elem)
    	return false;
    	
    temp = subRoot;
    
    
    if(isOrdered(subRoot->right, temp) == false)
    	return false;
    
    return true;
	
}
Exemple #7
0
bool isOrdered(List l)
{
	if (l == 0)
		return true;
	if (l->nextPtr == 0)
		return true;
	Data d1 = l->data;
	Data d2 = l->nextPtr->data;
	int cmp = compareData(d1, d2);
	if (cmp <= 0) {
		return isOrdered(l->nextPtr);
	} else {
		return false;
	}
}
void UmlReduceAction::write(FileOut & out) {
  write_begin(out, "ReduceAction");
  
  if (isOrdered())
    out << " isOrdered=\"true\"";
  
  write_end(out, TRUE);

  UmlItem * r = reducer();
  
  if (r != 0) {
    out.indent();
    out << "<reducer";
    out.idref(r);
    out << "/>\n";
  }

  write_close(out);
}
/*!
    Returns a deep-copied clone of the QMofStructuralFeature.
*/
QModelingElement *QMofStructuralFeature::clone() const
{
    QMofStructuralFeature *c = new QMofStructuralFeature;
    c->asQModelingObject()->setObjectName(this->asQModelingObject()->objectName());
    c->asQModelingObject()->setProperty("role", this->asQModelingObject()->property("role"));
    foreach (QMofComment *element, ownedComments())
        c->addOwnedComment(dynamic_cast<QMofComment *>(element->clone()));
    c->setName(name());
    c->setVisibility(visibility());
    c->setLeaf(isLeaf());
    c->setStatic(isStatic());
    c->setOrdered(isOrdered());
    c->setUnique(isUnique());
    if (lowerValue())
        c->setLowerValue(dynamic_cast<QMofValueSpecification *>(lowerValue()->clone()));
    if (upperValue())
        c->setUpperValue(dynamic_cast<QMofValueSpecification *>(upperValue()->clone()));
    c->setReadOnly(isReadOnly());
    return c;
}
Exemple #10
0
void UmlRelation::gen_uml_decl()
{
    if (isClassMember())
        fw.write("static, ");

    write(visibility());
    writeq(roleName());
    fw.write(" : ");
    roleType()->write();

    QByteArray s;

    s = defaultValue();

    if (!s.isEmpty()) {
        if (s[0] != '=')
            fw.write(" = ");

        writeq(s);
    }

    s = multiplicity();

    if (!s.isEmpty()) {
        fw.write(", multiplicity : ");
        writeq(s);
    }

    if (isDerived())
        fw.write((isDerivedUnion()) ? ", derived union" : ", derived");

    if (isReadOnly())
        fw.write(", read only");

    if (isOrdered())
        fw.write(", ordered");

    if (isUnique())
        fw.write(", unique");

}
Exemple #11
0
static void *getHead(void **tab, size_t n, size_t size, size_t sub, size_t *p_i1, size_t *p_i2,
		     CmpFunction cmpFunction, Order order)
{
  void *head;
  int out1, out2;

  out1 = sub + *p_i1 >= size || *p_i1 >= n;
  out2 = sub+n + *p_i2 >= size || *p_i2 >= n;
  if (out1 && out2)
    head = NULL;
  else if (out1)
    head = tab[sub+n + (*p_i2)++];
  else if (out2)
    head = tab[sub + (*p_i1)++];
  else
    {
      if (isOrdered(tab, sub + *p_i1, sub+n + *p_i2, cmpFunction, order))
	head = tab[sub + (*p_i1)++];
      else
	head = tab[sub+n + (*p_i2)++];
    }
  return head;
}
bool BinaryTree<T>::isOrdered() const
{
	Node * temp = NULL;	
	
    return isOrdered(root, temp);
}
Exemple #13
0
bool BinaryTree<T>::isOrdered() const
{
	return isOrdered(root);
}
Exemple #14
0
void UmlRelation::write_relation_as_attribute(FileOut & out) {
  UmlRelation * first = side(TRUE);
  Q3CString s;  
  UmlClass * base;

  if ((first->parent()->stereotype() == "stereotype") &&
      (first->roleType()->stereotype() == "metaclass")) {
    if (this != first)
      return;
    
    base = first->roleType();
    s = "base_" + base->name();
  }
  else {
    base = 0;
      
    switch (_lang) {
    case Uml:
      s = roleName();
      break;
    case Cpp:
      if (cppDecl().isEmpty())
	return;
      s = true_name(roleName(), cppDecl());
      break;
    default: // Java
      if (javaDecl().isEmpty())
	return;
      s = true_name(roleName(), javaDecl());
    }
  }
  
  out.indent();
  out << "<ownedAttribute xmi:type=\"uml:Property\" name=\"" << s << '"';
  out.id(this);
  
  if (base != 0)
    out.ref(first, "association", "EXT_");
  else {
    write_visibility(out);
    write_scope(out);
    if (isReadOnly())
      out << " isReadOnly=\"true\"";
    if (isDerived()) {
      out << " isDerived=\"true\"";
      if (isDerivedUnion())
	out << " isDerivedUnion=\"true\"";
    }
    if (isOrdered())
      out << " isOrdered=\"true\"";
    if (isUnique())
      out << " isUnique=\"true\"";
  
    if (first->_assoc_class != 0)
      out.ref(first->_assoc_class, "association");
    else
      out.ref(first, "association", "ASSOC_");
  
    out << " aggregation=\"";
    if (this == first) {
      parent()->memo_relation(this);
      if (_gen_eclipse) {
	switch (relationKind()) {
	case anAggregation:
	case aDirectionalAggregation:
	  out << "shared";
	  break;
	case anAggregationByValue:
	case aDirectionalAggregationByValue:
	  out << "composite";
	  break;
	default:
	  out << "none";
	}
      }
      else
	out << "none";
    }
    else if (_gen_eclipse)
      out << "none";
    else {
      switch (relationKind()) {
      case anAggregation:
      case aDirectionalAggregation:
	out << "shared";
	break;
      case anAggregationByValue:
      case aDirectionalAggregationByValue:
	out << "composite";
	break;
      default:
	out << "none";
      }
    }
    out << '"';
  }
  
  out << ">\n";
  out.indent(+1);
  
  out.indent();
  out << "<type xmi:type=\"uml:Class\"";
  if (base != 0) {
    if (! base->propertyValue("metaclassPath", s))
      s = (_uml_20) ? "http://schema.omg.org/spec/UML/2.0/uml.xml"
		    : "http://schema.omg.org/spec/UML/2.1/uml.xml";
    out << " href=\"" << s << '#' << base->name() << '"';
  }
  else
    out.idref(roleType());
  out << "/>\n";
  write_multiplicity(out, multiplicity(), this);
  write_default_value(out, defaultValue(), this);
  write_constraint(out);
  write_annotation(out);
  write_description_properties(out);
  
  out.indent(-1);
  out.indent();
  out << "</ownedAttribute>\n";

  unload();
}
std::unique_ptr<udt::Packet> NLPacketList::createPacket() {
    return NLPacket::create(getType(), -1, isReliable(), isOrdered());
}
Exemple #16
0
bool BinaryTree<T>::isOrdered() const
{
    // your code here
	return isOrdered((*this).root);
}
bool isOrdered(int* v, int i) {
    if(i==1) return v[1]>v[0];
    return isOrdered(v, i-1) && v[i]>v[i-1];
}