void mutableSquareImageContainer::
updateImageHistory(const QDomElement& element) {

  const QString toolFlossTypePrefix =
    ::getElementText(element, "tool_floss_type");
  if (!toolFlossTypePrefix.isNull()) {
    toolFlossType_ = flossType(toolFlossTypePrefix);
  }

  const QDomElement& historyElement = element.firstChildElement("history");
  // we put everything on forwardHistory_ and then moveHistoryForward()
  // the number of back_history items
  QDomElement backElement =
    historyElement.firstChildElement("backward_history");
  QDomNodeList backList(backElement.elementsByTagName("history_item"));
  for (int i = 0, size = backList.size(); i < size; ++i) {
    forwardHistory_.
      push_back(historyItem::xmlToHistoryItem(backList.item(i).toElement()));
  }

  QDomElement forwardElement =
    historyElement.firstChildElement("forward_history");
  QDomNodeList forwardList(forwardElement.elementsByTagName("history_item"));
  for (int i = 0, size = forwardList.size(); i < size; ++i) {
    forwardHistory_.
      push_back(historyItem::xmlToHistoryItem(forwardList.
                                              item(i).toElement()));
  }

  // move forward over the back history items
  for (int i = 0, size = backList.size(); i < size; ++i) {
    moveHistoryForward();
  }
}
Exemple #2
0
//privilegia o estudante, logo, comeca com a universidade escolhendo o estudante
void SMP_heuristica1 (StudentList* studentList, UniversityList* universityList) {
    while (!AllApproved (studentList)){
        University* university = frontList(universityList->list_);
        while (university != backList(universityList->list_)){        
                 Student* student_univList = frontList((University*) university->prefs_);
            while ( student_univList != backList(universityList->list_) ) {
                if (student_univList->status_ < 1 || 
                    StudentPrefersUniversity(student_univList, university) == 1){
                    AllocOnUniversity(university,student_univList);
                } else {
                    student_univList = nextList((University*) university->prefs_, student_univList);
            }
            university = nextList(universityList, university);
        }
    }
}
Exemple #3
0
int AllApproved(StudentList* studList){
    Node* node = frontList(studList->list_);
    while ( node != backList(studList->list_) ) {
        if (isApproved((Student*) getInfo(node))){
            return 0;
        }
        node = nextList(studList->list_, node);
    }
    return 1;
}
int main(int argc, char* argv[]) {
    printf("implement testLinkedList.c!\n");
    
    struct linkedList *lst;
    lst = createLinkedList();
    
    printf("isEmptyList?%i\n", isEmptyList(lst));
    
    printf("\nTesting add links (3),5,6,9,8\n");
    addList(lst, 5);
    printf("addList 5:%i\n", frontList(lst));
    addBackList(lst, 6);
    printf("backList 6:%i\n", backList(lst));
    addBackList(lst, 9);
    printf("backList 9:%i\n", backList(lst));
    
    addFrontList(lst,3);
    printf("frontList 3:%i\n", frontList(lst));
    
    addBackList(lst, 8);
    printf("backList 8:%i\n\n", backList(lst));
    
    printf("frontList 3:%i\n", frontList(lst));
    printf("backList 8:%i\n\n", backList(lst));
    
    printf("remove the front(3) and back(8)...\n");
    removeFrontList(lst);
    printf("frontList should now be 5:%i\n", frontList(lst));
    removeBackList(lst);
    printf("backList should now be 9:%i\n", backList(lst));
    
    printf("contains 5?%i\n",containsList(lst,5));
    printf("removing 5...");
    removeFrontList(lst);
    printf("contains 5?%i\n",containsList(lst,5));
    
    printf("removing 6...");
    removeList(lst,6);
    printf("frontList? 9:%i", frontList(lst));
    printf("isEmptyList?%i\n", isEmptyList(lst));
    
    return 0;
}
Exemple #5
0
void* CreateOutput(FILE* output, int word_counter, int char_counter, List* words){
    int l = 0;
    Node* node;
    fprintf(output,"%d\n%d\n",char_counter, word_counter);
    for (node = frontList(words); node != backList(words); node = node->next_){
        l++;
        fprintf(output,"%s ", node->suggest_ );
        if(l==word_counter) break;
    }
}
Exemple #6
0
//Funcao que checa se o Estudante prefere outra Universidade a de entrada da funcao. 
//Se preferir id2, retorna 1.
int StudentPrefersUniversity(Student* student, University* university){
    Node* node = frontList(student->preferences_->list_);
    while ( node != backList(student->preferences_->list_) ) {
        if ( university->key_ == (int*) getInfo(node)){
            return 1;
        } else {
            return 0;
        }
    }
		node = nextList(student->preferences_->list_, node);
}
Exemple #7
0
void PrintList(List* list) {
    Node* node;
    printf("LIST = ");
    int i = 0;
    for (node = frontList(list); node != backList(list); node = node->next_) {
        printf("%s ", node->info_);
        i++;
        if(i==12) {
            break;
        }
    }
    printf("\n");
}
Exemple #8
0
int main(int argc, char* argv[]) {
    int returned = -1;
    struct linkedList* q = createLinkedList(3);
    printf("Checking if the list is empty: %d\n", isEmptyList(q));
    
    printf("Attempting to add to front \n");
    addFrontList(q, 1);
    removeList(q, 1);
    printf("Checking if the list is empty: %d\n", isEmptyList(q));
    addFrontList(q, 2);
    addFrontList(q, 3);
    _printList(q);
    
    printf("Attempting to add to back \n");
    addBackList(q, 4);
    addBackList(q, 5);
    addBackList(q, 6);
    _printList(q);
    
    printf("Attempting to print front \n");
    printf("%d\n", frontList(q));
    
    printf("Attempting to print back \n");
    printf("%d\n", backList(q));
    
    printf("Attempting to remove front \n");
    removeFrontList(q);
    _printList(q);
    
    printf("Attempting to remove back \n");
    removeBackList(q);
    _printList(q);
    
    printf("Attempting to delete 4 \n");
    removeList(q, 4);
    _printList(q);
    
    printf("Attempting to print list \n");
    _printList(q);
    
    printf("Attempting to confirm contains 5 \n");
    returned = containsList(q, 5);
    if (returned == 1)
        printf("true \n");
    else
        printf("false \n");
    
    return 0;
}
Exemple #9
0
int main(){

	struct bag* b = (struct bag*)malloc(sizeof(struct bag));/*Create new bag*/
	initBag(b);/*Initialize*/

    printf("size of list = %d \n", b->lst->size);
    printf("\n");

    addFrontList(b->lst, 3);
    addFrontList(b->lst, 2);
    addBackList(b->lst, 4);
    addBackList(b->lst, 5);
    addBackList(b->lst, 6);
    addFrontList(b->lst, 1);

    int i;
    struct DLink *currentlink = b->lst->head->next;
    for(i = 1; i <= b->lst->size; i++){
            printf("index %d = %d \n", i, currentlink->value);
            currentlink = currentlink->next;
    }
    printf("\n");
    printf("front = %d \n", frontList(b->lst));
    printf("back = %d \n", backList(b->lst));
    printf("is list empty? = %d \n", isEmptyList(b->lst));
    printf("size of list = %d \n", b->lst->size);
    printf("list contains = %d \n", listContains(b->lst, 12));

    printf("\n");
    addToBag(b, 10);
    removeFromBag(b, 1);
    struct DLink *link = b->lst->head->next;
    for(i = 1; i <= b->lst->size; i++){
            printf("index %d = %d \n", i, link->value);
            link = link->next;
    }
    printf("list contains = %d \n", bagContains(b, 100));

    return 0;

}
Exemple #10
0
void FindMinorDistance(List* list ,FILE* dictionary, FILE* stopwords, int word_counter){
    char* dic = (char*)calloc(100,sizeof(char));
    char* stopw = (char*)calloc(100,sizeof(char));
    char* word = (char*)calloc(100,sizeof(char));
    char c;
    Node* node;
    int i=0;
    int j=0;
    int k=0;
    int l=0;
    for (node = frontList(list); node != backList(list); node = node->next_){

        strcpy(word,node->info_);
        //converting to lowercase 
        while(i < LengthStr(word)){
            c=word[i];
            word[i]=putchar(tolower(c));
            i++;
        }
         /////////////////////////////////////////
        //searching the words on the dictionary//
        ////////////////////////////////////////
        while(fscanf(dictionary,"%s", dic) >0) {
        
        //converting to lowercase 
            while(dic[j] < LengthStr(dic)){
                char c=dic[j];
                dic[j]=putchar(tolower(c));
                j++;
            }

            //if the words are equal, problem solved
            //if(EqualWords(node->info_,dic)==1){
            if(EqualWords(word,dic)==1){
                strcpy(node->suggest_,dic);
                //node->dif_= CalculatesDistance(node->info_, dic);
                node->dif_= CalculatesDistance(word, dic);

            //else, find the minor distance
            //} else if(CalculatesDistance(node->info_, dic) < node->dif_){
            } else if(CalculatesDistance(word, dic) < node->dif_){
                strcpy(node->suggest_,dic);
                //node->dif_= CalculatesDistance(node->info_, dic);
                node->dif_= CalculatesDistance(word, dic);
            }
        }

         ///////////////////////////////////////
        //searching the words on the stopwords//
        ///////////////////////////////////////
        while(fscanf(stopwords,"%s", stopw) >0) {


        //converting to lowercase 
            while(stopw[k] < LengthStr(stopw)){
                char c=stopw[k];
                stopw[k]=putchar(tolower(c));
                i++;
            }


            //if the words are equal, problem solved
            //if(EqualWords(node->info_,stopw)==1){
            if(EqualWords(word,stopw)==1){
                strcpy(node->suggest_,stopw);
             //   node->dif_= CalculatesDistance(node->info_, stopw);
                node->dif_= CalculatesDistance(word, stopw);

            //else, find the minor distance
           // } else if(CalculatesDistance(node->info_, stopw) < node->dif_){
            } else if(CalculatesDistance(word, stopw) < node->dif_){
                strcpy(node->suggest_,stopw);
                //node->dif_= CalculatesDistance(node->info_, stopw);
                node->dif_= CalculatesDistance(word, stopw);
            }
        }


        rewind(dictionary);
        rewind(stopwords);
        l++;
        if(l==word_counter) break;
    }
}
Exemple #11
0
void InsertBack (List* list, char* info) {
    insert(list, backList(list), info);
}