Esempio n. 1
0
void addbyRoot(char root[], char child[],int x, int y,tree *T){
	char amalan[50];
	int i;
	if (strcmp(root, "null")==0){
		makeTree(child, T);
		createList(&(*T).root->bad);
		for (i = 0; i < x; i+=1){
			scanf("%s", amalan);
			addLast(amalan, &(*T).root->bad);
		}
		createList(&(*T).root->good);
		for (i = 0; i < y; i+=1){
			scanf("%s", amalan);
			addLast(amalan, &(*T).root->good);
		}
	}else{
		simpul *node=findsimpul(root, (*T).root);
		addChild(child, node);
		node=findsimpul(child, node);
		for (i = 0; i < x; i+=1){
			scanf("%s", amalan);
			addLast(amalan, &node->bad);
		}
		createList(&(*T).root->good);
		for (i = 0; i < y; i+=1){
			scanf("%s", amalan);
			addLast(amalan, &node->good);
		}
	}
}
Esempio n. 2
0
void CCreatureAnim::loopPreview(bool warMachine)
{
	std::vector<EAnimType> available;

	static const EAnimType creaPreviewList[] = {HOLDING, HITTED, DEFENCE, ATTACK_FRONT, CAST_FRONT};
	static const EAnimType machPreviewList[] = {HOLDING, MOVING, SHOOT_UP, SHOOT_FRONT, SHOOT_DOWN};
	auto & previewList = warMachine ? machPreviewList : creaPreviewList;

	for (auto & elem : previewList)
		if (anim->size(elem))
			available.push_back(elem);

	size_t rnd = CRandomGenerator::getDefault().nextInt(available.size() * 2 - 1);

	if (rnd >= available.size())
	{
		EAnimType type;
		if ( anim->size(MOVING) == 0 )//no moving animation present
			type = HOLDING;
		else
			type = MOVING;

		//display this anim for ~1 second (time is random, but it looks good)
		for (size_t i=0; i< 12/anim->size(type) + 1; i++)
			addLast(type);
	}
	else
		addLast(available[rnd]);
}
Esempio n. 3
0
NodeL *getLfromT(NodeT *root)
{
    if(root==NULL)
    addLast("*");
    else
    {
            addLast(root->data);
            getLfromT(root->left);
            getLfromT(root->right);
    }
    return head;
}
Esempio n. 4
0
static void solveMaze(void)
{
    int x, y, offset;


    for (y = 0; y < height; y ++)
	for (x = 0; x < width; x ++)
	    maze[y][x].visited = false;

    y = 0;
    x = 0;

    while (y != height - 1 || x != width - 1) {
	draw(x, y, true);
	maze[y][x].visited = true;

	if (!maze[y][x].right && !maze[y][x + 1].visited) {
	    addLast(dp, offset(x + 1, y));
	    maze[y][x + 1].from = 1;
	}

	if (!maze[y][x].bottom && !maze[y + 1][x].visited) {
	    addLast(dp, offset(x, y + 1));
	    maze[y + 1][x].from = width;
	}

	if (x > 0 && !maze[y][x - 1].right && !maze[y][x - 1].visited) {
	    addLast(dp, offset(x - 1, y));
	    maze[y][x - 1].from = -1;
	}

	if (y > 0 && !maze[y - 1][x].bottom && !maze[y - 1][x].visited) {
	    addLast(dp, offset(x, y - 1));
	    maze[y - 1][x].from = -width;
	}

	if (getLast(dp) == offset(x, y)) {
	    draw(x, y, false);
	    removeLast(dp);
	}

	offset = getLast(dp);
	x = xcoord(offset);
	y = ycoord(offset);
    }

    draw(width - 1, height - 1, true);
}
Esempio n. 5
0
 int main(int argc, char *argv[]) {
     if (argc<2) return 0;
     FILE *f = fopen(argv[1],"r");
     if (f==NULL) return 0;
     struct List *l;
     newList(&l);
     char x[20];
     struct Entry* node;
     struct Entry* n1 ;
     newNode(&n1);
     n1->element = "N1";
     struct Entry* n2 ;
    newNode(&n2);
    n2->element = "N2";
     struct Entry* n3 ;
     newNode(&n3);
     n3->element = "N3";
     struct Entry* n4 ;
     newNode(&n4);
     n4->element = "N4";
     int status = 0;
     struct Entry* e = l->head;
     while (fscanf(f,"%s",x)==1) {
        if (x[0] == '"')
             continue;
         if (strcmp(x,"N1")==0)
             node = n1;
         if (strcmp(x,"N2")==0)
             node = n2;
         if (strcmp(x,"N3")==0)
             node = n3;
         if (strcmp(x,"N4")==0)
             node = n4;
         if (strcmp(x,"H")==0)
             node = l->head;
         addLast(&l,&node);
     }
    fclose(f);

    if (hasLoopNext(l)==0  ){
        printf("%s","HAS LOOP");
        return 0;
    }

    if (hasLoopPrev(l)==0  ){
        printf("%s","HAS LOOP");
        return 0;
    }

    struct Entry* n = l->head->next;
    while (n != (l->head)) {
        printf("%s ", n->element);
        printf("%s ", n->previous->element);
        printf("%s ", n->previous->element);
        n = n->next;
    }
    printf(" %d",l->size);
    return 0;

}
Esempio n. 6
0
void preorder(nodeT* tempNode, nodeL** listNode)
{
    if(tempNode != NULL)
    {
        char* tempData = (char*)malloc(sizeof(char)*100);
        itoa(tempNode->data, tempData, 10);
        addLast(listNode, tempData);

        preorder(tempNode->left, listNode);
        preorder(tempNode->right, listNode);
    }
    else
    {
        addLast(listNode, "*");
    }
}
Esempio n. 7
0
/* Adds a command to the history list, deleting the first if the 
* size of the list is too large */
void addCommandToHistory(char* command_line)
{
    history_item* theItem = (history_item*)malloc(sizeof(history_item));
    
    if(history_list == NULL)
    {
        initHistory();
    }
    if(length(history_list) == 0)
    {
        theItem->command_number = 1;
    }
    else
    {
        theItem->command_number = 
            1 + ((history_item*)(history_list->tail->data))->command_number;
    }
    
    theItem->command_line = command_line;

    addLast(history_list, theItem);
    if(length(history_list) > HISTORY_LENGTH)
    {
        free(((history_item*)(history_list->head->data))->command_line);
        free(history_list->head->data);
        removeFirst(history_list);
    }
}
Esempio n. 8
0
void insrt(unsigned int p,int x)
{
    if (p==0)
        addFirst(x);
    else
    if (p>=lngth)
        addLast(x);
    else
    {
        int i;
        node *n=(node*)malloc(sizeof(node));
        node *t;
        if (p<=lngth/2)
            for (i=0, t=f;i+1<p;i++)///p is unsigned=> can't use p-1
                t=t->next;
        else
            for (i=lngth,t=l;i>p;i--)
                t=t->prev;
        n->val=x;
        n->prev=t;
        n->next=t->next;
        (t->next)->prev=n;
        t->next=n;
    }

    lngth++;
}
Esempio n. 9
0
void main(int argc, char** argv) {
  addFirst(5);
  addFirst(2);
  addFirst(3);
  addLast(4);
  displayFrom(head);
}
Esempio n. 10
0
bool Sequence<TYPE>::add(const TYPE &value, int pos)
 {
    Node *aux = &list;
    Node *aux7 = &list;
    while (aux->next != NULL)
    {
        if(pos < 0)
            return addFirst(value);
        else
        {
            if(pos == 0)
            {
                if(aux->next != NULL)
                {
                    Node *aux5 = new Node;
                    aux5->data=value;
                    aux5->next=aux->next;
                    aux5->prev=aux->prev;
                    aux->next = aux5;
                    return true;
                }
                else
                    break;
            }
        }
        pos--;
        aux = aux->next;
    }
    if(aux7->next != NULL)
        addLast(value);
    return false;
}
Esempio n. 11
0
/****************** Function that creates a list from a bin tree ****/
nodeL * getListFromTree(nodeT * root)
{
    if (root==NULL)
    {
        char * data=malloc(sizeof(char)*10);
        strcpy(data,"*");
        addLast(&headG,data);
        return 0;
    }
    {
        addLast(&headG,root->data);
        getListFromTree(root->left);
        getListFromTree(root->right);
    }
    return headG;
}
Esempio n. 12
0
int main()
{
    Sant* santi=(Sant*)malloc(sizeof(Sant));
    initializeSent(santi);
    //santi->head=NULL;
    // santi->tail=NULL;
    char s[30];
    int x;
    out=fopen("out.txt","w");
    in=fopen("in.txt","r");
    int c;
    c=fscanf(in,"%s %d",s,&x);
    while(c>0)
    {
        //printf("%s %d\n",s,x);
        if(!strcmp(s,"AL"))addLast(santi,x);
        if(!strcmp(s,"AF"))addFirst(santi,x);
        if(!strcmp(s,"DE"))delete_element(santi,x);
        if(!strcmp(s,"PRINT_F"))print_first(santi,x);
        if(!strcmp(s,"PRINT_L"))print_last(santi,x);
        if(!strcmp(s,"PRINT_ALL"))printlist(santi);
        if(!strcmp(s,"DOOM_THE_LIST"))doom_the_list(santi);
        if(!strcmp(s,"DF"))delete_first(santi);
        if(!strcmp(s,"DL"))delete_last(santi);
        strcpy(s,"");
        c=fscanf(in,"%s %d",s,&x);

    }
    return 0;
}
Esempio n. 13
0
/**
 * Generate and print a random clause with nbLiterals literals
 * @param f the formula
 * @param clauseNumber : the clause to generate
 * @param : the number of literals that contain the clause

 */
void generateClause(Formula f,int clauseNumber, int nbLiterals) {
  for(int i = 0;i<nbLiterals;i++) {
    int sign = rand()%2 ? 1 : -1;
    Literal l = sign*(rand()%f.nbVariables+1);
    addLast(&(f.clauses[clauseNumber]),l);
  }
}
Esempio n. 14
0
void initPost(Sequence* mid, Sequence* post) {
    Stack stack;
    initStack(&stack);
    for (int i = 0; i < mid->used; i++) {
        if ((mid->ele + i)->isOperator) {
            porcessOperator(mid, post, i, &stack);
        } else {
            addLast(post, *(mid->ele + i));
        }
    }
    while (!isEmpty(&stack)) {
        ExpressionEle topEle;
        pop(&stack, &topEle);
        addLast(post, topEle);
    }
}
Esempio n. 15
0
void initMid(Sequence* midSequence, char* strMid) {
    int i = 0;
    while (strMid[i] != '\0') {
        ExpressionEle ele;
        initEle(&ele, strMid, &i);
        addLast(midSequence, ele);
    }
}
Esempio n. 16
0
void processRightBracket (Sequence* mid, Sequence* post, 
        int midIndex, Stack* pStack) {
    ExpressionEle topEle;
    pop(pStack, &topEle);
    while (topEle.operator != '(') {
        addLast(post, topEle);
        pop(pStack, &topEle);
    }
}
Esempio n. 17
0
int main()
{

    sent = (list*)malloc(sizeof(list));
    sent->head = NULL;
    sent->tail = NULL;
    sent->len = 0;


    FILE*  fin= fopen("input.txt", "r");

    char caz[20];
    int n;

    while(fscanf(fin, "%s", caz)>0)
    {
        if(strcmp(caz, "AF")==0)
        {
            fscanf(fin, "%d", &n);
            addFirst(n);
        }
        else if(strcmp(caz, "AL")==0)
        {
            fscanf(fin, "%d", &n);
            addLast(n);
        }
        else if(strcmp(caz, "DF")==0)
            deleteFirst();
        else if(strcmp(caz, "DL")==0)
            deleteLast();
        else if(strcmp(caz, "DOOM_THE_LIST")==0)
            doomTheList();
        else if(strcmp(caz, "DE")==0)
        {
            fscanf(fin, "%d", &n);
            deleteX(n);
        }
        if(strcmp(caz, "PRINT_ALL")==0)
            printList();
        else if(strcmp(caz, "PRINT_F")==0)
        {
            fscanf(fin, "%d", &n);
            printFirstX(n);
        }
        else if(strcmp(caz, "PRINT_L")==0)
        {
            fscanf(fin, "%d", &n);
            printLastX(n);
        }
    }

    fclose(fin);
    return 0;
}
Esempio n. 18
0
inline
bool
DLFifoListImpl<P,T,U>::seizeLast(Ptr<T> & p)
{
  if (likely(thePool.seize(p)))
  {
    addLast(p);
    return true;
  }
  p.p = NULL;
  return false;
}
Esempio n. 19
0
int main()
{
	int argc;
	char **argv = NULL, s[MAX];
	LinkedList * myList = linkedList();
  
  	printf("command?: ");
  	fgets(s, MAX, stdin);
  	strip(s);

  	while(strcmp(s, "exit") != 0)
  	{
		if(strcmp(s, "history") == 0)
      {
			argc = makeargs(s, &argv);
			addLast(myList, buildNode_Type(buildType_Args(argc, argv)));
         printList(myList, printType);
      }
		else
		{
			argc = makeargs(s, &argv);
			addLast(myList, buildNode_Type(buildType_Args(argc, argv)));

		}// end else

		printf("command?: ");
	  	fgets(s, MAX, stdin);
      strip(s);	 

  	}// end while

	clearList(myList, cleanType);
   	free(myList);
   	myList = NULL;

   	printf("Program Ended\n");

  	return 0;

}// end main
Esempio n. 20
0
//Gets the numbers from the user
// O(n) n being the number of items the user enters
void getNumbers(DEQUE *maindeque, int *max){
    int x;
    *max = 0;
    printf("Enter numbers to sort, type s to stop:\n");
    while(scanf("%d", &x) == 1){
        if(x < 0){
            printf("%d not accepted, enter positive numbers only or s to stop\n", x);
            continue;
        }
        addLast(maindeque, x);
        if(*max < x) *max = x;
    }
}
Esempio n. 21
0
List* createList(FILE* in) {
	List* l = newList();

	char *pc = (char*)malloc(20 * sizeof(char));

	while (!feof(in)) {
		fscanf(in, "%s ", pc);
		addLast(l, pc);
	}

	free(pc);
	return l;
}
Esempio n. 22
0
void addToHistory(char * s)
{
	History * h = (History *)calloc(1, sizeof(History));

	int l = strlen(s);
	(*h).line = (char*)calloc(l + 1, sizeof(char));
	strncpy((*h).line, s, l);

	Node * nn = buildNode_Type(h);

	trimList();

	addLast(HISTORY, nn);
}
Esempio n. 23
0
void command(char* s, LinkedList* historyList)
{
	int preCount = 0, postCount = 0, pipeCount = 0, argc;
	char **prePipe = NULL, **postPipe = NULL, **argv = NULL;

	while(strcmp(s, "exit") != 0)
	{
		char s2[50];
		strcpy(s2, s);
		strip(s2);
		argc = makeargs(s2, &argv);
		addLast(historyList, buildNode_Type(buildType_Args(argc, argv)));
		memset(&s2[0], 0, sizeof(s2));

		pipeCount = containsPipe(s);
		if(pipeCount > 0)
		{
			prePipe = parsePrePipe(s, &preCount);
			postPipe = parsePostPipe(s, &postCount);
			pipeIt(prePipe, postPipe, historyList);
			clean(preCount, prePipe);
			clean(postCount, postPipe);
		}// end if pipeCount

		else
		{
			if(strcmp(argv[0],"cd") != 0) {
				if (argc != -1)
					forkIt(argv, historyList);
			}
			else
				myDir(argv);
		}
		//	clean(argc, argv);
		//	argv = NULL;

		//printList(historyList,printType);

		memset(&s[0], 0, sizeof(s));
		printf("\ncommand?: ");
		fgets(s, MAX, stdin);
		strip(s);

	}// end while




}
Esempio n. 24
0
bool ossimImageChain::insertLeft(ossimConnectableObject* newObj,
                                 ossimConnectableObject* leftOfThisObj)
{
   if(!theImageChainList.size())
   {
      return add(newObj);
   }
   
   if(findObject(leftOfThisObj, false))
   {
      std::vector<ossimRefPtr<ossimConnectableObject> >::iterator iter = theImageChainList.begin();

      while(iter != theImageChainList.end())
      {
         if( (*iter) == leftOfThisObj)
         {
            break;
         }
         ++iter;
      }
      if(leftOfThisObj==theImageChainList[theImageChainList.size()-1].get())
      {
         return addLast(newObj);
      }
      else if(PTR_CAST(ossimImageSource, newObj))
      {
         ossimConnectableObject::ConnectableObjectList inputList = leftOfThisObj->getInputList();
         leftOfThisObj->disconnectAllInputs();
         newObj->connectInputList(inputList);
         leftOfThisObj->connectMyInputTo(newObj);
         newObj->changeOwner(this);
         newObj->addListener((ossimConnectableObjectListener*)this);
         theImageChainList.insert(iter+1, newObj);
         if (newObj)
         {
            // Send an event to any listeners.
            ossimContainerEvent event(this, newObj, OSSIM_EVENT_ADD_OBJECT_ID);
            fireEvent(event);
         }
         return true;
      }
   }

   return false;
}
Esempio n. 25
0
bool ossimSingleImageChain::addImageHandler(const ossimFilename& file, bool openOverview)
{
   bool result = false;

   close();
   
   // m_handler = ossimImageHandlerRegistry::instance()->open(file, true, openOverview);
   m_handler = ossimImageHandlerRegistry::instance()->openConnection(file, openOverview);
   
   if ( m_handler.valid() )
   {
      // Add to the chain.  Note: last is really first.
      addLast( m_handler.get() );
      
      result = true;
   }

   return result;
}
Esempio n. 26
0
void BadtoGood(list *L, list *L2, list *A, list *B){  
	int stat=0;
	if((*L).first != NULL && (*A).first!=NULL){
		/*jika list tidak kosong*/
		/*inisialisasi*/
		elemen *elmt = (*L).first;
		elemen *elmt2, *prev;
		// int i = 1;

		while(elmt != NULL){
		/*proses*/
		// printf("%s\n", elmt->elmt.amal);
		elmt2 = (*A).first;
			while(elmt2 != NULL){
				if (strcmp(elmt->elmt.amal, elmt2->elmt.amal)==0){
					stat=1;
					if (elmt==(*L).first)
					{
						delFirst(L);
					}else{
						delAfter(prev, L);
					}
				}
				elmt2 = elmt2->next;
			}
		/*iterasi*/
		prev = elmt;
		elmt = elmt->next;
		// i = i + 1;
		}
		if (stat==1 && (*B).first!=NULL){
			elmt2 = (*B).first;			
			// int i = 1;
			while(elmt2 != NULL){
			/*proses*/
			// printf("%s\n", elmt2->elmt2.amal);
				addLast(elmt2->elmt.amal, L2);
			elmt2 = elmt2->next;
			}
		}
	}
}
void addToRoom(int client_sockfd, int newRoom, int prevRoom, int prevSpot)
{
	int i;

	// if client was in a previous room, take him out and place him into new room
	if(prevRoom != -1 && prevSpot != -1)
	{
		if(prevSpot >= MAX_CLIENTS)
		{
			// the client wants to join a new room but is in a queue for an old room
			// take client out of queue, pop DOESN'T WORK BECAUSE CLIENT MIGHT BE IN THE MIDDLE OF THE QUEUE
			//pop(&queue[prevRoom]);
			
		}
		else
		{
			clientsConnected[prevRoom][prevSpot] = 0;
			population[prevRoom]--;
			queueToRoom(prevRoom, prevSpot);
		}
	}

	if(population[newRoom] == MAX_CLIENTS)
	{
		//put client into queue
		write(client_sockfd, "The room is full.\nEither join another room or wait till someone leaves to be automatically joined.", strlen("The room is full.\nEither join another room or wait till someone leaves to be automatically joined."));
		addLast(&queue[newRoom], client_sockfd);
	}
	else
	{
		for(i = 0; i < MAX_CLIENTS; i++)
		{
			if(clientsConnected[newRoom][i] == 0)
			{
				clientsConnected[newRoom][i] = client_sockfd;
				population[newRoom]++;
				break;
			}
		}
	}
}
Esempio n. 28
0
void porcessOperator(Sequence* mid, Sequence* post, 
        int midIndex, Stack* pStack) {
    char current = (mid->ele + midIndex)->operator;
    if (current == ')') {
        processRightBracket(mid, post, midIndex, pStack);
        return;
    }
    ExpressionEle topEle;
    bool getSuccess = getTop(pStack, &topEle);
    if (!getSuccess || //栈是空的直接进栈或者当前符号大于栈顶元素直接进栈
            !currentLessEqualTop(current, topEle.operator)) {
        push(pStack, *(mid->ele + midIndex));
        return;
    }
    do { 
        pop(pStack, &topEle);
        addLast(post, topEle);
        getSuccess = getTop(pStack, &topEle);
    } while((getSuccess && currentLessEqualTop(current, topEle.operator)));
    push(pStack, *(mid->ele + midIndex));
}
Esempio n. 29
0
 int main(int argc, char *argv[]) {
     if (argc<2) return 0;
//     FILE *f = fopen(argv[1],"r");
//     if (f==NULL) return 0;
     struct List *l;
     newList(&l);
     char* x = argv[1];
     char* tmp;
     tmp = strtok(x," ");
     struct Entry* node;
     struct Entry* n1 ;
     newNode(&n1);
     n1->element = "N1";
     struct Entry* n2 ;
    newNode(&n2);
    n2->element = "N2";
     struct Entry* n3 ;
     newNode(&n3);
     n3->element = "N3";
     struct Entry* n4 ;
     newNode(&n4);
     n4->element = "N4";
     int status = 0;
     struct Entry* e = l->head;
     while (tmp != (void*)0) {
        if (tmp[0] == '"')
             continue;
         if (strcmp(tmp,"N1")==0)
             node = n1;
         if (strcmp(tmp,"N2")==0)
             node = n2;
         if (strcmp(tmp,"N3")==0)
             node = n3;
         if (strcmp(tmp,"N4")==0)
             node = n4;
         if (strcmp(tmp,"H")==0)
             node = l->head;
         addLast(&l,&node);
         tmp = strtok((void*)0," ");
     }

    if (hasLoopNext(l)==0  ){
        printf("%s","HAS LOOP");
        return 0;
    }

    if (hasLoopPrev(l)==0  ){
        printf("%s","HAS LOOP");
        return 0;
    }

    struct Entry* n = l->head->next;
    while (n != (l->head)) {
        printf("%s ", n->element);
        printf("%s ", n->previous->element);
        printf("%s ", n->previous->element);
        n = n->next;
    }
    printf(" %d",l->size);
    return 0;

}
Esempio n. 30
0
 T&              addLast     (const T& item)                 { T& slot = addLast(); slot = item; return slot; }