コード例 #1
0
ファイル: main.c プロジェクト: davidphan75/Permutation
void permutateVector(cVector *baseVec, cVector *buildVec){

    
    // If the base vector is empty then we have created a new permutaion
    // stored in the build vector and we print this vector
    if (baseVec->count == 0) {
        if (calculate(buildVec)) {
            printf("Solution: ");
            printVector(buildVec);
        }
        
    // Otherwise we pop an element off the base vector and append it to
    // the build vector
    }else{
        for (int i = 0; i < baseVec->count; i++) {
            int number = popFront(baseVec);
            pushBack(buildVec, number);
            permutateVector(baseVec, buildVec);
        }
    }
    
    // when finishes permutating a each level restore the previous
    if (buildVec->count != 0) {
        int x = popBack(buildVec);
        pushBack(baseVec, x);

    }
    
}
コード例 #2
0
ファイル: main.c プロジェクト: sachin-rajput/basic-ds-algo
int main(int argc, char* argv[])
{

#if DEBUG
	printf("\n>>==============Debug Value Set=================<<\n");
#endif
	char* file = argv[1];
	linkList *newlinkList = readData(file,1);
	//linkList *newlinkList = readData(file,2); //adding from back
	addatPosition(newlinkList,10,45);
	popFront(newlinkList);
	popBack(newlinkList);
	popatPosition(newlinkList,7);
	popwithValue(newlinkList,45);
	printlinkList(newlinkList);
	int value_f = 222;
	int i = searchValue(newlinkList,value_f);
#if DEBUG
	if(i == 1)
		printf(">>==============Search: Value %d found=================<<\n",value_f);
	else
		printf(">>==============Search: Value not found=================<<\n");
#endif

	cleanlinkList(newlinkList);
	return 0;
}
コード例 #3
0
ファイル: dlinklist.c プロジェクト: pravs-naksh/CS-snippets
//search for element in dlinklist, if found remove.
void searchRemove(dlinklist *ll,char val){
	node *temp = ll->head;
       // node *prev = temp;
        data *tempdata;
        while(temp != NULL){
                if(temp->d->val == val){
                        //element found!
                        if(temp == ll->head){
                                tempdata = popFront(ll);
                                //prev = ll->head;
                        } else if(temp == ll->tail){
                                tempdata = popBack(ll);
                        } else {
                                temp->prev->next = temp->next;
                                temp->next = NULL;
                                tempdata = temp->d;
                        }
                        free(tempdata);
                        free(temp);
                        if(temp->prev == NULL) temp = temp->prev;
                        else temp = temp->prev->next;
                } else {
                        //prev = temp;
                        temp = temp->next;
                }
        }
}
コード例 #4
0
void List::clear()
{
    while(countOfElements != 0) {
        popBack();
    }

}
コード例 #5
0
ファイル: OStateStack.cpp プロジェクト: spzktshow/OriginArt
void StateStack::stopExecute()
{
	while (_stack.size() > 0)
	{
		popBack();
	}
}
コード例 #6
0
bool DLList::removeFirst(int target) {
    DLNode* toRemove = NULL;
    DLNode* nodeMark = head;
    DLNode* lagMark = NULL;
    for (unsigned int i = 0; i < count; i++){
        if (nodeMark->getContents() != target && nodeMark->getNext() != NULL){
            lagMark = nodeMark;
            nodeMark = nodeMark->getNext();
        } else if (nodeMark->getContents() == target){
            toRemove = nodeMark;
        }
    }
    if (toRemove == NULL) {
        return false;
    }
    if (lagMark == NULL){
        popFront();
    } else if (toRemove->getNext() == NULL) {
        popBack();
    } else {
        count--;
        nodeMark = nodeMark->getNext();
        lagMark->setNext(nodeMark);
        nodeMark->setPrevious(lagMark);
        delete toRemove;
    }
    toRemove = NULL;
    nodeMark = NULL;
    lagMark = NULL;
    return true;
}
コード例 #7
0
ファイル: LinkedList.cpp プロジェクト: kjwill555/Queue_KW_LN
void LinkedList<T>::deleteAt(int index) {
	if (index == 0) { //just delete the front
		popFront();
	}
	else if (index == length-1) { //just delete the back
		popBack();
	}
	else if (index < 0 || index >= length) { //index is not valid
		std::cout << "Invalid index" << endl;
		return;
	}
	else {
		Node<T>* currentAtIndex = first;
		for (int i = 0; i < index; i++) { //find the desired node to be deleted
			currentAtIndex = currentAtIndex->getNext();
		}
		Node<T>* before = first;
		while (before->getNext() != currentAtIndex) { //find the node before the one to be deleted
			before = before->getNext();
		}
		before->setNext(currentAtIndex->getNext());
		currentAtIndex->setNext(nullptr);
		length--;
	}
}
コード例 #8
0
/***
 * search for element in dlinklist, if found remove.
 */
void searchRemove(dlinklist *ll,float val)
{
	node *temp = ll->head;
	data *tempdata;
	while(temp != NULL) {
		if(temp->dataPtr->val == val) {
			//element found!
			if(temp == ll->head) {
				popFront(ll);
			} else if(temp == ll->tail) {
				popBack(ll);
			} else {
				temp->prev->next = temp->next;
				temp->next = NULL;
				tempdata = temp->dataPtr;
				free(tempdata);
				free(temp);
			}
#if DEBUG
			printf(">>==============Node with value: %f pop'd ================<<\n",val);
#endif
			return;
		} else {
			temp = temp->next;
		}
	}
}
コード例 #9
0
/**
 * Remove from position i of the linkList
 */
void popatPosition(dlinklist *ll,int position)
{
    if(!checkEmpty(ll)) return;
    int length = listSize(ll);
    if(position > length) {
        printf("You entered the position out of the bound!\n");
        return;
    }
    node *temp;
    int i = 1;

    if(position == 1) {
        //pop here - popFront and return;
        popFront(ll);
    } else if(position == length) {
        //pop here - popBack and return;
        popBack(ll);
    }

    for(temp= ll->head; temp != NULL; temp=temp->next) {
        if(i == position) {
            //pop here and return;
            temp->prev->next = temp->next;
            temp->next->prev = temp->prev;
#if DEBUG
            printf(">>==============Node pop'd at position %d ================<<\n",position);
#endif
            free(temp->dataPtr);
            free(temp);
            return;
        }
        i++;
    }
}
コード例 #10
0
ファイル: undomanager.cpp プロジェクト: QuLogic/ScribusCTL
void UndoManager::disconnectGuis()
{
	for (uint i = 0; i < undoGuis_.size(); ++i)
	{
		UndoGui *gui = undoGuis_[i];

		disconnect(gui, SIGNAL(undo(int)), this, SLOT(undo(int)));
		disconnect(gui, SIGNAL(redo(int)), this, SLOT(redo(int)));
		disconnect(this, SIGNAL(newAction(UndoObject*, UndoState*)),
                   gui, SLOT(insertUndoItem(UndoObject*, UndoState*)));
		disconnect(this, SIGNAL(popBack()), gui, SLOT(popBack()));
		disconnect(this, SIGNAL(undoSignal(int)), gui, SLOT(updateUndo(int)));
		disconnect(this, SIGNAL(redoSignal(int)), gui, SLOT(updateRedo(int)));
		disconnect(this, SIGNAL(clearRedo()), gui, SLOT(clearRedo()));
		gui->setEnabled(false);
	}
}
コード例 #11
0
void List::clear()
{
    while(countOfElements != 0) {
        popBack();
    }
    delete head;
    delete last;

}
コード例 #12
0
ファイル: heapApp.c プロジェクト: pravs-naksh/CS-snippets
void printHeap(heap *h){
	data **listCor = (data**)malloc(sizeof(data*)*10);
	int i = 0;
	while(h->root){
		if(i>9){
			popBack(h->q->ll);
			break;
		}
		leaf *rootleaf = removeRoot(h);
		
#if DEBUG		
		printf("removing data %f at %d \n",rootleaf->d->distance,i);
#endif
		
		listCor[i] = createData(rootleaf->d->valx,rootleaf->d->valy);
		listCor[i]->distance = calculateDistance(listCor[i]->valx,listCor[i]->valy);
		
		if(h->root == rootleaf){
			free(h->root->d);
			free(h->root);
			h->root = NULL;
		} else {
			free(rootleaf->d);
			free(rootleaf);
		}

		popBack(h->q->ll);
		i++;	
	}
	
	for(i = 9;i>=0;i--){
		printf(" %.2f %.2f %.2f \n",listCor[i]->distance,listCor[i]->valx,listCor[i]->valy);
		data *d = createData(listCor[i]->valx,listCor[i]->valy);
		d->distance = calculateDistance(d->valx,d->valy);
		addLeaf(h,d);
		free(listCor[i]);
	}
	
	free(listCor);
}
コード例 #13
0
ファイル: task_3(dek).cpp プロジェクト: GNazar/tasks_3
int _tmain(int argc, _TCHAR* argv[])
{
	for(int i=(int)0;i<4;i++){
		pushBack(i*i);
	}
	puts("print()");
	print();
	getchar();

	puts("insertAt(1,-100)");	//insert element;
	insertAt((int)1,(int)-100);
	print();
	getchar();

	puts("popFront()");		//delete first element; 
	popFront();
	print();
	getchar();

	puts("popBack()");		//delete last element;
	popBack();
	print();
	getchar();

	puts("pushFront(-1)");	//insert element at first position;
	pushFront((int)-1);
	print();
	getchar();

	printf("at(3)=%d\n",at((int)3));//get 3rd element;
	getchar();

	puts("insertAt(size,-3)");	//delete element;
	insertAt(size,(int)-3);
	print();
	getchar();

	puts("deleteAt(1)");	//delete element;
	deleteAt((int)1);
	print();
	getchar();

	puts("Free list");		//delete all elements;
	delDEQ();
	print();
	getchar();
	return 0;
}
コード例 #14
0
ファイル: undomanager.cpp プロジェクト: QuLogic/ScribusCTL
void UndoManager::action(UndoObject* target, UndoState* state, QPixmap *targetPixmap)
{
	QPixmap *oldIcon = 0;
	if (targetPixmap)
	{
		oldIcon = target->getUPixmap();
		target->setUPixmap(targetPixmap);
	}

	if (!undoEnabled_) // if so flush down the state
	{
		TransactionState *ts = dynamic_cast<TransactionState*>(state);
		if (ts) // flush the TransactionObject too
			delete target;
		delete state;
		return;
	}

	if (!isTransactionMode() &&
        (currentUndoObjectId_ == -1 || currentUndoObjectId_ == static_cast<long>(target->getUId())))
	{
//		qDebug() << "UndoManager: new Action" << state->getName() << "for" << currentUndoObjectId_;
		emit newAction(target, state); // send action to the guis
	}
	else
	{
		emit clearRedo();
	}
	if (isTransactionMode())
	{
//		qDebug() << "UndoManager: Action stored for transaction:" << transactions_.back() << target->getUName() << state->getName();
		transactions_.back()->transactionState->pushBack(target, state);
	}
	else
	{
//		qDebug() << "UndoManager: Action executed:" << target->getUName() << state->getName();
		state->setUndoObject(target);
		if (stacks_[currentDoc_].action(state))
			emit popBack();
	}
	if (targetPixmap)
		target->setUPixmap(oldIcon);

	setTexts();
}
コード例 #15
0
ファイル: calculator.cpp プロジェクト: lkpdn/tcalc
void Calculator::push_button(btn_t bt) {
    switch (bt) {
    case btn_t::btn_clr:
        main_display->clearEquation();
        buffered_equation.clear();
        buffered_partial_op_string.clear();
        break;
    case btn_t::btn_bck:
        main_display->popBack();
        popBack();
        break;
    default:
        auto attr = getButtonAttribute(bt);
        main_display->pushBack(attr.label);
        buffered_equation.push_back(attr.inner_rep);
    }
    main_display->redisplay();
};
コード例 #16
0
ファイル: heapApp.c プロジェクト: pravs-naksh/CS-snippets
heap* getData(char *file){
	FILE* input_file = fopen(file,"r");
	if(input_file == NULL){
		printf("Error opening input file %s\n",file);
		exit(1);
	}
	float inputx = 0.0;
	float inputy = 0.0;	
	heap *newheap = createHeap();
	int i = 0;
	while(fscanf(input_file, "%f", &inputx) != EOF){
		fscanf(input_file, "%f", &inputy);
		data *d= createData(inputx,inputy);
		d->distance = calculateDistance(d->valx,d->valy);
		if(i>9){
			if(d->distance < newheap->root->d->distance){
				leaf *removeleaf = removeRoot(newheap);
#if DEBUG
				printf("deleted : %f and inserted : %f -- \n",removeleaf->d->distance,d->distance);
#endif
				popBack(newheap->q->ll);
				free(removeleaf->d);
				free(removeleaf);
				addLeaf(newheap,d);
			} else {
#if DEBUG			
				printf("Skipped : %f => ",d->distance);
				printf("deleting ...... \n");
#endif
				free(d);
			}
		}
		else { 	
#if DEBUG		
			printf("inserted : %f -- \n",d->distance);
#endif
			addLeaf(newheap,d);
		}
		i++;
	}
	
	fclose(input_file);
	return newheap;
}
コード例 #17
0
ファイル: dl_list.cpp プロジェクト: Dminer001/CSCI-21
/**
  * Removes all occurences of the parameter
  * does nothing if not in list
  */
  bool DLList::removeAll(string contents)
  {
       //returns false for empty list
     if (head_ == NULL)
     {
         return false;
       // uses popBack() if tail == contents
     } else if (tail_->getContents() == contents)
     {
         popBack();
         return true;
     } else 
     {
         //creating pointers
         DLNode* iterator = head_, *temp = head_->getNext();
         //traverses to find match for contents
         while (contents != temp->getContents() && temp->getNext() != NULL)
         {
             temp = temp->getNext();
             iterator = iterator->getNext();
         }
     //returns false if contents are not in list
     if (temp == tail_ && temp->getContents() != contents)
     {
         return false;
     
     } else
     //checks if temp is the node to delete then executes
     while (temp != NULL)
     {
         if(temp->getContents() == contents)
         {
             iterator->setNext(temp->getNext());
             delete temp;
             size_ = size_ - 1;
             temp = NULL;
             
         }
     }
         
     } 
     return true;
  }
コード例 #18
0
ファイル: task_3(dek).cpp プロジェクト: GNazar/tasks_3
//function delete element by it position;
int deleteAt(int pos)
{
	DEQ*pel=front;
	int res;
	int i=(int)0;
	if(pos<=(int)0)
		return popFront();	//delete first element;
	if(pos>size)
		return popBack();	//delete last element;
	while(i<pos){			//find element;
		i++;
		pel=pel->next;
	}
	res=pel->data;
	pel->prev->next=pel->next;
	pel->next->prev=pel->prev;
	size--;
	delete pel;
	return res;
}
コード例 #19
0
//remove the first instance of a DLNode containing target; do nothing if target is not found
bool DLList::removeFirst (int target)
{
    if(head == NULL)
    {
        return false;
    }
    else if(head->getContents()==target)
    {
        popFront();
        return true;
    }
    else
    {
        DLNode* temp = head;
        while(temp->getNext() != NULL)
        {
            DLNode* nextTemp = temp->getNext();
            if(temp->getContents() == target)
            {
                temp->getPrevious()->setNext(nextTemp);
                nextTemp->setPrevious(temp->getPrevious());
                
                delete temp;
                size--;
                if(size == 1)
                {
                    head = tail;
                }
                return true;
            }
            temp = temp->getNext();
        }
        if(temp->getContents() == target)
        {
            popBack();
            return true;
        }
        return false;
    }
}
コード例 #20
0
ファイル: sums.c プロジェクト: alexdalton/pepper
void findPathRecursive(node * root, int expectedSum, int currentSum, vector * path)
{
    currentSum += root->value;
    pushBack(path, root->value);

    if( currentSum == expectedSum && root->left == NULL && root->right == NULL)
    {
        int i;
        for (i = 0; i <= path->back; i++)
        {
            printf("%d ", path->contents[i]);
        }
        printf("\n");
    }
    if (root->left != NULL)
        findPathRecursive(root->left, expectedSum, currentSum, path);
    if (root->right != NULL)
        findPathRecursive(root->right, expectedSum ,currentSum, path);

    if (!isEmpty(path))
        popBack(path);
}
コード例 #21
0
ファイル: main.c プロジェクト: sachin-rajput/basic-ds-algo
int main(int argc, char* argv[])
{

#if DEBUG
	printf("\n>>==============Debug Value Set=================<<\n");
#endif
	char* file = argv[1];
	dlinklist *newdlinklist = readData(file,1);
	//linkList *newlinkList = readData(file,2); //adding from back
	addatPosition(newdlinklist,2,4.5);
	popFront(newdlinklist);
	popBack(newdlinklist);
	popatPosition(newdlinklist,7);
	popwithValue(newdlinklist,32.34);
	printList(newdlinklist);
	reverseList(newdlinklist);
	printList(newdlinklist);
	float value_f = 33.4;
	searchRemove(newdlinklist,value_f);
	cleanList(newdlinklist);
	return 0;
}
コード例 #22
0
bool DLList::removeFirst(string target) {
    if(head_node == NULL) {
        return false;
    }
    
    DLNode* temp = head_node;
    DLNode* previous = temp;
    if(head_node->getContents() == target) {
        cout << "Eliminated " << target << endl;
        popFront();
        return true;
    }
    if(tail_node->getContents() == target) {
        cout << "Eliminated " << target << endl;
        popBack();
        return true;
    }
    // There is no reason why this loop would be endless, so there won't be a catch.
    // The incoming TARGET string is only called when getStop finishes.
    while(temp->getContents() != target) {
        // Get next node and continue, and keep previous 1 behind.
        previous = temp;
        temp = temp->getNext();
    }
    
    if(temp->getContents() == target) {
        cout << "Eliminated " << target << endl;
        // Delete Node
        // Setting previous' node to the next node of temp
        previous->setNext(temp->getNext());
        // Setting temp's next node's PREVIOUS to temp's previous NODE
        temp->setPrevious(temp->getPrevious());
        delete temp;
        temp = NULL;
        node_count--;
        return true;
    } else {
        cout << "RemoveFirst returned false entirely (bad?)"<<endl;return false;}
}
コード例 #23
0
/**
 * remove all instances of DLNode containing target; do nothing if target 
 * is not found
 */
 bool DLList::removeAll(int target) 
 {
    /**
     * Checks if the head is null and returns false if it is
     */
    if(head_ == NULL)
    {
      return false;
    /**
     * Checks if the contents of head_ are equal to the parameter, then
     * calls the popBack() function and returns true if it is
     */
    } else if(head_->getContents() == target)
    {
      popBack();
    /**
     * Checks if the contents of tail_ are equal to the parameter, then
     * calls the popBack() function and returns true if it is
     */
    } else if(tail_->getContents() == target)
    {
      popBack();
    /**
     * checks if the list contains only two nodes, if it does not then
     * it checks for the specified parameter, otherwise it returns false
     */
    } else if(head_->getNext() != tail_)
    {
      DLNode* iterator = head_->getNext();
      DLNode* temp_node = head_;
      /**
       * Loops through the node list checking the contents of the current
       * node to the parameter and if the next node is the tail, if neither
       * statement is true then it iterates to the next node
       */
      while(iterator->getContents() != target && iterator->getNext() != tail_)
      {
        temp_node = iterator;
        iterator = iterator->getNext();
      }
      /**
       * Checks if the contents of the current node are equal to the parameter,
       * if not then returns false
       */
      if(iterator->getContents() == target)
      {
        /**
         * Sets the placeholder node to the node that the iterator is pointing
         * to then deletes the iterator node, reduces the size variable
         * then returns true
         */
        temp_node->setNext(iterator->getNext());
        delete iterator;
        iterator = NULL;
        count_ = count_ - 1;
      } else
      {
        return false;
      }
    } else
    {
      return false;
    }
    return true;
 }
コード例 #24
0
ファイル: NavPath.cpp プロジェクト: Jamsterx1/Liquid-Engine
 const NavNode& NavPath::loopBack()
 {
     pushFront(mNodes.back());
     return popBack();
 }
コード例 #25
0
ファイル: GLinkList.cpp プロジェクト: lecai/gods
inline GLinkObject* GLinkList::pop(bool front) {
    return front? popFront(): popBack();
}
コード例 #26
0
ファイル: Queue.hpp プロジェクト: giftnuss/libftl
	inline T popBack() { T item; popBack(item); return item; }
コード例 #27
0
ファイル: list.cpp プロジェクト: Ashatta/study
void remove(Node * guard)
{
    while (!isEmpty(guard))
        popBack(guard);
    delete guard;
}
コード例 #28
0
ファイル: ABasePtrQueue.hpp プロジェクト: achacha/AOS
template<class T> T* popBack(size_t index = 0)  { return dynamic_cast<T *>(popBack(index)); }
コード例 #29
0
void DLList::clear() {
    for (unsigned int i = 0; i < count;){
        popBack();
    }
}
	void	popBack			(T* elemBuf, int count) { peekBack(elemBuf, count); popBack(count); }