Esempio n. 1
0
RetValue
FIND_MAXIMUM_SUBARRAY(int* A, int low, int high)
{
  RetValue ret;
  if(high == low) { // 1
    ret.max_left = low;
    ret.max_right = high;
    ret.sum = A[low];
#ifdef DEBUG
    printRet(ret);
#endif
    return ret; // 2 base case: only one element
  } else {
    int mid = (low + high) / 2; // 3
#ifdef DEBUG
    printf("FIND_MAXIMUM_SUBARRAY(low: %d, mid: %d)\n", low, mid);
#endif
    RetValue leftRet = FIND_MAXIMUM_SUBARRAY(A, low, mid); // 4
#ifdef DEBUG
    printf("FIND_MAXIMUM_SUBARRAY(mid+1: %d, high: %d)\n", mid+1, high);
#endif
    RetValue rightRet = FIND_MAXIMUM_SUBARRAY(A, mid + 1, high); // 5
#ifdef DEBUG
    printf("FIND_MAX_CROSSING_SUBARRAY(low: %d, mid: %d, high: %d)\n", low, mid, high);
#endif
    RetValue crossRet = FIND_MAX_CROSSING_SUBARRAY(A, low, mid, high); //6
#ifdef DEBUG
    printf("leftRet ");printRet(leftRet);
    printf("rightRet ");printRet(rightRet);
    printf("crossRet ");printRet(crossRet);
#endif
    if (leftRet.sum >= rightRet.sum && leftRet.sum >= crossRet.sum){ // 7
#ifdef DEBUG
      printf("Choose left\n");      
#endif
      return leftRet; // 8
    } else if (rightRet.sum >= leftRet.sum && rightRet.sum >= crossRet.sum){ // 9
#ifdef DEBUG
      printf("Choose right\n");
#endif
      return rightRet; // 10
    } else {
#ifdef DEBUG
      printf("Choose cross\n");
#endif
      return crossRet; // 11
    }
  }
}
Esempio n. 2
0
void printStmtList (struct STMT *st) {
	if (st == NULL) {
		//fprintf (stderr, "Statement list does not exist.\n");
		return;
	}

	if (st->prev != NULL)
		printStmtList (st->prev);

	if (st->s == eAssign) {
		printAssi (st->stmt.assign_);
		fprintf (fp, ";\n");
	}
	else if (st->s == eCall) {
		printCall (st->stmt.call_);
		fprintf (fp, ";\n");
	}
	else if (st->s == eRet) {
		printRet (st->stmt.return_);
		fprintf (fp, ";\n");
	}
	else if (st->s == eWhile) {
		printWhil (st->stmt.while_);
		fprintf (fp, "\n");
	}
	else if (st->s == eFor) {
		printFor (st->stmt.for_);
		fprintf (fp, "\n");
	}
	else if (st->s == eIf) {
		printIf (st->stmt.if_);
		fprintf (fp, "\n");
	}
	else if (st->s == eCompound) {
		printCompStmt (st->stmt.cstmt_);
	}
	else if (st->s == eSwitch) {
		printSwit (st->stmt.switch_);
		fprintf (fp, "\n");
	}
	else
		fprintf (fp, ";\n");
}
Esempio n. 3
0
int
Write (
  sEvent *sp,
  FILE *outFile
)
{
  switch (sp->EventType) {
  case mh_eEvent_Alarm:
  case mh_eEvent_MaintenanceAlarm:
  case mh_eEvent_SystemAlarm:
  case mh_eEvent_UserAlarm1:
  case mh_eEvent_UserAlarm2:
  case mh_eEvent_UserAlarm3:
  case mh_eEvent_UserAlarm4:
  case mh_eEvent_Info:
    printMess(sp, outFile);
    break;
  case mh_eEvent_Ack:
    printAck(sp, outFile);
    break;
  case mh_eEvent_Cancel:
  case mh_eEvent_Return:
    printRet(sp, outFile);
    break;
  case mh_eEvent_Block:
  case mh_eEvent_Unblock:
  case mh_eEvent_Reblock:
  case mh_eEvent_CancelBlock:
    printBlock(sp, outFile);
    break;
  default:
    printf("rt_elog_dump: Error in Write unknown EventType");
    break;
  }  
  return 1;
}