Beispiel #1
0
void test_findLast(){
  ArrayUtil a = create(4,5);
  int * list_array = (int *)(a.base);
  list_array[0] = 12;
  list_array[1] = 25;
  list_array[2] = 34;
  list_array[3] = 45;
  list_array[4] = 5;
  
  assert(*(int *)findLast(a, &isEven, NULL) == 34);

  int x = 5;
  assert(*(int *)findLast(a, &isDivisible, &x) == 5);
};
struct ifStatement* ifSt()
{	
	struct ifStatement* ifstmt;
	struct statementNode* noop;
	ifstmt = make_ifSt();

	ifstmt->condition = condition();
	ttype = getToken();
	if(ttype == LBRACE)
	{
		//body
		ifstmt->stmt_list = stmt_list();
		
		noop = make_stmt(NOOPSTMT);
		//find last stmt stmt ->next = noop;
		findLast(ifstmt->stmt_list)->next = noop;
		
		//true
		ifstmt->condition->trueBranch = ifstmt->stmt_list;
		
		//false
		//noop = make_stmt(NOOPSTMT);
		//find last stmt stmt ->next = noop;
		ifstmt->condition->falseBranch = noop;
		
		return ifstmt;
	}
	else
	{
		return NULL;
	}
}
struct statementNode* stmt_list()
{ 
	struct statementNode* st; // statement
	struct statementNode* st1; // statement list
	struct statementNode* no_op;
	struct statementNode* gt;

	st = stmt();
	
	if(ttype == RBRACE)
	{
		getToken();
	}
	
	ttype = getToken();
	//printf("TTYPE before %d\n",ttype);
	if (((ttype == ID)||(ttype == WHILE)||(ttype == PRINT)||(ttype == IF)))
	{		
		//printf("TTYPE after %d\n",ttype);
		ungetToken();
		st1 = stmt_list();
		

		
		findLast(st)->next = st1; //stmt head
		stmt_head = st;
		return st;
	}
	
	else
	{	
		return st;
	}
}
Beispiel #4
0
SEXP interp_walk(SEXP x, SEXP env, SEXP data)  {
  if (!Rf_isLanguage(x))
    return x;

  if (is_call_to(x, "uq")) {
    SEXP uq_call = PROTECT(Rf_lang3(Rf_install("uq"), CADR(x), data));
    SEXP res = PROTECT(Rf_eval(uq_call, env));
    UNPROTECT(2);
    return res;
  }

  if (is_call_to(x, "uqf")) {
    return Rf_eval(x, env);
  }

  // Recursive case
  for(SEXP cur = x; cur != R_NilValue; cur = CDR(cur)) {
    SETCAR(cur, interp_walk(CAR(cur), env, data));

    SEXP nxt = CDR(cur);
    if (is_call_to(CAR(nxt), "uqs")) {
      // uqs() does error checking and returns a pair list
      SEXP args_pl = Rf_eval(CAR(nxt), env);

      // Insert args_pl into existing pairlist of args
      SEXP last_arg = findLast(args_pl);
      SETCDR(last_arg, CDR(nxt));
      SETCDR(cur, args_pl);
    }
  }
  return x;
}
Beispiel #5
0
Value *findLastProperRec(Value* value){
  if (!(value->cons->cdr)) {
    return value;
  } 
  else
    return findLast(value->cons->cdr);
}
Beispiel #6
0
void delAt(List &L, address Data){
	address P,prev,last;
	if(!isEmpty(L) && Data!=NULL)
	{
		prev=P=L.First;
		last=findLast(L);
		
		do
		{
			if(P==Data)
			{
				if(P==L.First) 
				{
					L.First=L.First->Next;
					last=L.First;
				}
				else 
				{
					prev=prevNode(L,Data);
					prev->Next=Data->Next;
				
				}
				delete(Data);
				return;
			}
			P=P->Next;
		}while(P->Next!=L.First);
	}
}
Beispiel #7
0
	void getBoundingBox(ofImage& img, ofRectangle& box, int thresh, bool invert) {
		Mat mat = toCv(img);
		int flags = (invert ? THRESH_BINARY_INV : THRESH_BINARY);
		
		Mat rowMat = meanRows(mat);
		threshold(rowMat, rowMat, thresh, 255, flags);
		box.y = findFirst(rowMat, 255);
		box.height = findLast(rowMat, 255);
		box.height -= box.y;
		
		Mat colMat = meanCols(mat);
		threshold(colMat, colMat, thresh, 255, flags);
		box.x = findFirst(colMat, 255);
		box.width = findLast(colMat, 255);
		box.width -= box.x;
	}
Beispiel #8
0
Node* copyList(Node* header){
    Node* retList = createList();
    Node* tmp = header->next;
    while (tmp != NULL) {
        insertNode(tmp->data, findLast(retList));
        tmp = tmp->next;
    }
    return retList;
}
Beispiel #9
0
PMETHOD objrtn findLast(object self, ifun cfun, object *foundKey)
{ BTreeNode_iv_t *iv = GetIVs(BTreeNode, self);
	if (iv->iType == 2) { 
		if (foundKey) 
			*foundKey = iv->iKeys[iv->iUsed-1]; 
		return iv->iObjects[iv->iUsed-1]; 
	} 
	return findLast(iv->iObjects[iv->iUsed], cfun, foundKey); 
} 
Beispiel #10
0
void test_findLast_returns_NULL_if_none_of_the_elements_matches_criteria () {
	int array[] = {1,7,3,9,5};
	int *element;
	ArrayUtil util = create(4, 5);
	insertElements(&util, array);
	element = findLast(util, isEven, NULL);
	assert(element==NULL);
	dispose(util);
}
Beispiel #11
0
void test_findLast(){
  ArrayUtil a = create(4,5);
  int * list_array = (int *)(a.base);
  list_array[0] = 12;
  list_array[1] = 25;
  list_array[2] = 34;
  list_array[3] = 45;
  list_array[4] = 5;
  
  assert(*(int *)findLast(a, &isEven, NULL) == 34);
  printf("findLast finds the last even number of the list\n");

  int x = 5;
  assert(*(int *)findLast(a, &isDivisable, &x) == 5);
  printf("findLast finds the last divisable number by 5 from the list\n");

  dispose(a);
}
Beispiel #12
0
void test_findLast_returns_pointer_of_the_first_element_from_last_that_matches_criteria_for_isDivisible() {
	int array[] = {1,2,3,4,5};
	int a = 5;
	int *element;
	ArrayUtil util = create(4, 5);
	insertElements(&util, array);
	element = findLast(util, isDivisible, &a);
	assert(*element==5);
	dispose(util);
}
Beispiel #13
0
void test_findLast_returns_NULL_if_none_of_the_elements_matches_criteria_for_isDivisible () {
	int array[] = {1,2,3,4,5};
	int *element;
	int a = 7;
	ArrayUtil util = create(4, 5);
	insertElements(&util, array);
	element = findLast(util, isDivisible, &a);
	assert(element==NULL);
	dispose(util);
}
Beispiel #14
0
void WinFilePath::setString(const TCHAR *string)
{
  StringStorage::setString(string);
  if (!isEmpty()) {
    if (findLast('/') == 0) {
      m_parentPathIsRoot = true;
    }
    convertToWindowsPath();
  }
}
int main()
{
	int t,a,b;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&a,&b);
		printf("%d\n",findLast(a,b));
	}
	return 0;
}
Beispiel #16
0
struct statementNode* findLast(struct statementNode* cur)
{
	if(cur->next == NULL)
	{
		return cur;
	}
	else
	{
		return (findLast(cur->next));
	}
}
int findLast(int a,int b)
{
	int t;
	if(b==0)
		return 1;
	else if(b==1)
		return a%MOD;
	t=findLast(a,b/2);
	if(b%2==0)
		return (t*t)%MOD;
	else return (t*t*a)%MOD;
}
void test_18_findLast_should_find_last_element_for_integers(){
	arrayUtil util = create( sizeof(int), 3);
	int* result;
	int* base;
	int hint = 3;
	base = (int*) util.baseAddress;
	base[0] = 9;
	base[1] = 33;
	base[2] = 54;
	result = findLast(util, isDivisible, &hint);
	ASSERT(54 == *result);
}
Beispiel #19
0
// 计算字符串计算式s的值
int calc(char* s)
{
    int n = 0;

    n = findLast(s, '*');
    if (-1 != n)
        return calc(leftStr(s, n)) * calc(rightStr(s, n));
    n = findLast(s, '/');
    if (-1 != n)
        return calc(leftStr(s, n)) / calc(rightStr(s, n));

    n = findLast(s, ')');
    int m = findLast(s, '(');
    if (-1 != n && -1 != m)
    {
        int i;
        char temp[strlen(s) + 1];
        int j = 0;
        for (i = m + 1; i < n; i++)
            temp[j++] = s[i];
        return calc(temp);
    }
    // 找到最后一个加号
    n = findLast(s, '+');
    if (-1 != n)
        // 以加号所在的位置,将字符串分为左右两部分分别计算
        // 然后将两部分的值加起来
        return calc(leftStr(s, n)) + calc(rightStr(s, n));
    n = findLast(s, '-');
    if (-1 != n)
        return calc(leftStr(s, n)) - calc(rightStr(s, n));

    // 当字符串中不包含运算符时,返回这个数字本身
    return atoi(s);
}
 vector<int> searchRange(vector<int>& nums, int target) {
     int length = nums.size();
     if(length == 0)
         return vector<int>(2, -1);
     int start = -1, end = -1;
     start = findFirst(nums, target);
     if(start != -1)
         end = findLast(nums, target);
     vector<int> result;
     result.push_back(start);
     result.push_back(end);
     return result;
 }
Beispiel #21
0
void insertLast(List &L, address P){
	address temp;
	if(isEmpty(L))
	{
		insertFirst(L,P);
	}
	else
	{
		temp=findLast(L);
		temp->Next=P;
		P->Next=L.First;
		
	}
}
Beispiel #22
0
void test2_for_findLast(){
 ArrayUtil a = create(4,6);
  ((int *)a.base)[4] = 3;
  ((int *)a.base)[3] = 4;
  ((int *)a.base)[2] = 10;
  ((int *)a.base)[1] = 8;
  ((int *)a.base)[5] = 11;
  ((int *)a.base)[0] = 9;
  int divisor = 17;
  void * hint = &divisor;
  MatchFunc func = isDivisible;
  assert(NULL == (int *)findLast(a,&func,hint));
  printf("test passed\n\n");
};
Beispiel #23
0
//penyisipan
void insertFirst(List &L, address P){
	address last;
	if(isEmpty(L))
	{
		L.First=P;
		L.First->Next=L.First;
	}
	else
	{
		last=findLast(L);
		P->Next=L.First;
		L.First=P;
		last->Next=L.First;
	}
}
Beispiel #24
0
void test_check_divisibility_if_divisible_for_findLast(){
	Array_util a = create(sizeof(int), 4);
	int *arr = a.base;
	arr[0] = 12;
	arr[1] = 13;
	arr[2] = 14;
	arr[3] = 15;
	arr[4] = 16;
	
	int hint = 4;
	MatchFunc *match = &isDivisible;
	void * find = findLast(a, match, &hint); 
	int res = *(int *)find;
	assert(res == 16);
};
void test_19_findLast_should_find_last_element_for_string(){
	String *result;
	String *base;
	arrayUtil util;
	int hint = 5;
	int res;
	util = create( sizeof(String),3);
	base = util.baseAddress;
	strcpy(base[0],"soumya");
	strcpy(base[1],"kashish");
	strcpy(base[2],"mohit");
	result = findLast(util, isLengthEqualTo, &hint);
	res = strcmp(*result,"mohit");
	if(res==0)
		ASSERT(1);
}
void toTemplateEdit::remove(void)
{
    if (LastTemplate != TemplateMap.end())
    {
        toTreeWidgetItem *item = findLast();
        TemplateMap.erase(LastTemplate);
        LastTemplate = TemplateMap.end();
        Name->setText(QString::null);
        Description->setText(QString::null);
        if (item)
        {
            connectList(false);
            clearUnused(Templates->firstChild(), "");
            connectList(true);
        }
    }
}
Beispiel #27
0
void addLastL(NodeL** head, char* data)
{
    if((*head)==NULL)
    {
        (*head)=(NodeL*)malloc(sizeof(NodeL));
        (*head)->data=data;
        (*head)->next=NULL;
        (*head)->prev=NULL;
    }
    else
    {
        NodeL* nnew=(NodeL*)malloc(sizeof(NodeL));
        nnew->data=data;
        nnew->next=NULL;
        NodeL* tail=findLast(*head);
        nnew->prev=tail;
        tail->next=nnew;
    }
}
Beispiel #28
0
void HTMLEntitySearch::advance(UChar nextCharacter) {
  ASSERT(isEntityPrefix());
  if (!m_currentLength) {
    m_first = HTMLEntityTable::firstEntryStartingWith(nextCharacter);
    m_last = HTMLEntityTable::lastEntryStartingWith(nextCharacter);
    if (!m_first || !m_last)
      return fail();
  } else {
    m_first = findFirst(nextCharacter);
    m_last = findLast(nextCharacter);
    if (m_first == m_last && compare(m_first, nextCharacter) != Prefix)
      return fail();
  }
  ++m_currentLength;
  if (m_first->length != m_currentLength) {
    return;
  }
  m_mostRecentMatch = m_first;
}
Beispiel #29
0
int put_if_can(int i, int j)
{
	int v = findLast(i, j);
	int ok = 0;
	if (allnum[i][j] == 8) {
		ok = 1;
	} else if ((v = must_put_vertical(i, j)) != -1) {
		ok = 1;
	} else if ((v = must_put_grid(i, j)) != -1) {
		ok = 1;
	} else if ((v = must_put_horizontal(i, j)) != -1) {
		ok = 1;
	}
	if (ok == 1) {
		add_to_vertical(i, j, v);
		add_to_horizontal(i, j, v);
		add_to_grid(i, j, v);
		matrix[i][j] = v;
		all[i][j][v] = 1;
		allnum[i][j] = 9;
	}
}
Beispiel #30
0
///
/// Main program
///
int main(int argc, char *argv[]) {
    int c, i, o;
    unsigned int n;
    FILE *src, *dst;
    
    while(1) {
        c = getopt(argc, argv, "o:i:f");
        
        if (c == -1) {
            break;
        }
        
        switch(c) {
            
            case 'o':
                strncpy(cFileName, optarg, STRLEN);
                break;

            case 'i':
                strncpy(arrayName, optarg, STRLEN);
                break;

            case 'f':
                force = 1;
                break;
            
            case '?':
                usage();
                return -1;
        }
    }
    
    if (optind == argc-1) {
        strncpy(bitFileName, argv[optind], STRLEN);
    } else {
        usage();
        return -1;
    }

    if (strlen(cFileName) == 0) {
        strncpy(cFileName, bitFileName, STRLEN-2);
        strcat(cFileName, ".c");
    }
    
    // if cFileName ends in ".c", replace that by ".h", otherwise just append ".h"
    if (strcmp(cFileName + strlen(cFileName)-2, ".c") == 0) {
        strcpy(hFileName, cFileName);
        hFileName[strlen(cFileName)-2] = 0;
    } else {
        strncpy(hFileName, cFileName, STRLEN-2);
    }
    strcat(hFileName, ".h");
    
    // if none given, generate array name
    if (strlen(arrayName) == 0) {
        // use everything after last '/'
        if (findLast(bitFileName, "/") != NULL) {
            strncpy(arrayName, findLast(bitFileName, "/")+1, STRLEN);
        } else {
            strncpy(arrayName, bitFileName, STRLEN);
        }
    }
    // replace '.' with '_'
    for (i = 0; i < strlen(arrayName); i++) {
        if (arrayName[i] == '.') {
            arrayName[i] = '_';
        }
    }
        
    // generate size name
    strncpy(sizeName, arrayName, STRLEN-5);
    for (i = 0; i < strlen(sizeName); i++) {
        sizeName[i] = toupper(sizeName[i]);
    }
    strcat(sizeName, "_SIZE");

    // write C source
    src = fopen(bitFileName, "rb");
    if (src == NULL) {
        perror("error opening file");
        return -1;
    }

    o = findSyncWord(src);
    if (o < 0) {
        if (!force) {
            fprintf(stderr, "no sync word in bitstream\n");
            fclose(src);
            return -1;
        } else {
            o = 4;
        }
    } 

    dst = fopen(cFileName, "w");
    if (dst == NULL) {
        perror("error opening file for writing");
        fclose(src);
        return -1;
    }
    
    n = writeCFile(src, dst, o-4);
    fclose(src);
    fclose(dst);
    if (n == 0) {
        fprintf(stderr, "error while writing C source\n");
        return -1;
    }
    
    // write header
    dst = fopen(hFileName, "w");
    if (dst == NULL) {
        perror("error opening file for writing");
        return -1;
    }
    writeHFile(n, dst);
    fclose(dst);
    
    return 0;
}