Example #1
0
	SLList<T>::~SLList()
	{
		while (!isEmpty())
		{
			popFront();
		}
	}
Example #2
0
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;
}
Example #3
0
//removes node from head
bool DLList::removeAll(int target)
{
    if (head == NULL)
        return false;
    else
    {
        DLNode* trailer = NULL;
        DLNode* spot = head;
        while(spot != NULL &&spot -> getContents() != target)
        {
            trailer = spot;
            spot = spot -> getNext();
        }
        if(spot == NULL)
            return false;
        else if(spot == head)
        {
            popFront();
            return true;
        }
        else
        {
            trailer -> setNext(spot->getNext());
            delete spot;
            count--;
            return true;
        }
    }
}
Example #4
0
void testTeil2 (t_Listenkopf *li)
{
	int i;
	char s[LAENGE];
	// Testfall 3:
	printf("Testfall 3: anfuegen und zeigen\n");
	for (i = 0; i < N; i++)
		pushBack(li, testListe[i]);

	printListe(li);
	Assert(li->anzahlElemente == N, "falsche Elementezahl");
#ifdef TEST
	printf("Press Enter...\n");
	while (getchar() != '\n');
#endif

	// Testfall 4
	printf("Testfall 4: pop einzeln\n");
	for (i = 0; i < N; i++)
	{
		popFront(li, s);
		printf("pop: %s  Rest: \n",s);
		Assert(strcmp(s, testListe[i])==0, "falsche Reihenfolge");//prüfen Folge
		Assert(li->anzahlElemente == (N-i-1), "falsche Elementezahl");//Anzahl
		printListe(li);
#ifdef TEST
	printf("Press Enter...\n");
	while (getchar() != '\n');
#endif
	}
	Assert(li->anzahlElemente == 0, "falsche Elementezahl");
}
Example #5
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;
}
Example #6
0
//removes head
void DLList::clearList()
{
    while (head != NULL)
    {
        popFront();
    }
}
Example #7
0
//
// RawWin32Mouse::processEvents
//
// Iterates our queue of RAWINPUT events and converts them to Doom event_t
// and posts them for processing by the game internals.
//
void RawWin32Mouse::processEvents()
{
	if (!mActive)
		return;

	event_t movement_event;
	movement_event.type = ev_mouse;
	movement_event.data1 = movement_event.data2 = movement_event.data3 = 0;

	const RAWMOUSE* mouse;
	while (mouse = front())
	{
		popFront();

		// process mouse movement and save it
		processRawMouseMovement(mouse, &movement_event);

		// process mouse button clicks and post the events
		event_t button_event;
		for (int i = 0; i < 5; i++)
		{
			if (processRawMouseButtons(mouse, &button_event, i))
				D_PostEvent(&button_event);
		}

		// process mouse scroll wheel action
		if (processRawMouseScrollWheel(mouse, &button_event))
			D_PostEvent(&button_event);
	}

	// post any mouse movement events
	if (movement_event.data2 || movement_event.data3)
		D_PostEvent(&movement_event);
}
Example #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;
		}
	}
}
Example #9
0
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);

    }
    
}
Example #10
0
void removeAllNodes(struct List *list){

  while(isEmptyList(list)!=1){
    popFront(list);// remove the first element until the end of the lsit
  }

}
Example #11
0
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--;
	}
}
Example #12
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++;
    }
}
Example #13
0
//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;
                }
        }
}
Example #14
0
//clear all nodes from list, reset size to zero, set head and tail to NULL
void DLList::clear ()
{
    while(head != NULL)
        popFront();
    size = 0;
    head = NULL;
    tail = NULL;
}
Example #15
0
/*
 *  Delete the entire list of users while sending a message to each of them 
 *
 */
void deleteListWithMessage(List *list, void (*fn)(int, char *)) {
  while (list->head) {
    UserData* temp = (UserData *)popFront(list);
    if(temp->loggedIn) {
      fn(temp->sockNum, "Logging off.");
    }
    free(temp);
  }
}
Example #16
0
bool
HeapSnapshot::init(JSContext* cx, const uint8_t* buffer, uint32_t size)
{
  if (!nodes.init() || !frames.init())
    return false;

  ArrayInputStream stream(buffer, size);
  GzipInputStream gzipStream(&stream);

  // First is the metadata.

  protobuf::Metadata metadata;
  if (!parseMessage(gzipStream, metadata))
    return false;
  if (metadata.has_timestamp())
    timestamp.emplace(metadata.timestamp());

  // Next is the root node.

  protobuf::Node root;
  if (!parseMessage(gzipStream, root))
    return false;

  // Although the id is optional in the protobuf format for future proofing, we
  // can't currently do anything without it.
  if (NS_WARN_IF(!root.has_id()))
    return false;
  rootId = root.id();

  // The set of all node ids we've found edges pointing to.
  NodeIdSet edgeReferents(cx);
  if (NS_WARN_IF(!edgeReferents.init()))
    return false;

  if (NS_WARN_IF(!saveNode(root, edgeReferents)))
    return false;

  // Finally, the rest of the nodes in the core dump.

  while (StreamHasData(gzipStream)) {
    protobuf::Node node;
    if (!parseMessage(gzipStream, node))
      return false;
    if (NS_WARN_IF(!saveNode(node, edgeReferents)))
      return false;
  }

  // Check the set of node ids referred to by edges we found and ensure that we
  // have the node corresponding to each id. If we don't have all of them, it is
  // unsafe to perform analyses of this heap snapshot.
  for (auto range = edgeReferents.all(); !range.empty(); range.popFront()) {
    if (NS_WARN_IF(!nodes.has(range.front())))
      return false;
  }

  return true;
}
Example #17
0
/**
 * clear all nodes from list, reset count to zero, set head and tail to NULL
 */
 void DLList::clear() 
 {
    while(head_ != NULL)
    {
      popFront();
    }
    delete head_;
    head_ = NULL;
    tail_ = NULL;
 }
Example #18
0
static bool
CheckMyHashMap(JSContext* cx, Handle<MyHashMap> map)
{
    for (auto r = map.all(); !r.empty(); r.popFront()) {
        RootedObject obj(cx, r.front().value());
        if (obj->as<NativeObject>().lastProperty() != r.front().key())
            return false;
    }
    return true;
}
Example #19
0
/**
 *  clears the entire contents of the list,
 *  freeing all memory associated with all nodes
 */
void DLList::Clear()
{

    while (head_ != NULL)
    {
        popFront();
    }
    head_ = NULL;
    tail_ = NULL;
    
}
Example #20
0
	void SLList<T>::remove(int pos)
	{
		SNode<T>* current = goTo(pos);
		if (pos == 0)
		{
			popFront();
		}
		else
		{
			goTo(pos - 1)->next = current->next;
		}
		delete current;
		size--;
	}
Example #21
0
void List::popBack(){
	if(head != 0){

		if(head == tail){
			popFront();
		}
		else{
			Node *temp = head;
			for(; temp->next != 0; temp = temp->next);
			delete tail;
			tail = temp;
		}
	}
}
Example #22
0
	void DLList<T>::remove(int pos)
	{
		if (pos == 0)
			popFront();
		else
		{
			DNode<T>* current = goTo(pos);
			T data = current->data;
			current->prev->next = current->next;
			if (current->next != nullptr)
				current->next->prev = current->prev;
			delete current;
			size--;
		}
	}
Example #23
0
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;
}
Example #24
0
void free_usb_device(UsbDevice * udev)
{
	List * listHook;
#ifdef __KERNEL__
	destroy_workqueue(udev->workqueue);
#endif
	while ( udev->endpoints_handles != NULL )
	{
		listHook = popFront(&udev->endpoints_handles);
		remove_endpoint_handle((EndpointHandle*)listHook->data);
		FREE(listHook);
	}

	removeList(&udev->detached_interfaces);

	FREE(udev->ctrl0_buf);
	FREE(udev);
}
Example #25
0
bool DLList::removeFirst(int target) {
  bool tFound = false;
  if (head == NULL)
    return tFound;
  else if (head -> getContents() == target) {
    popFront();
    tFound = true;
  } else 
    tFound = true;
    DLNode* targetFound = searchIndex(target);
    targetFound ->getPrevious() -> setNext(targetFound ->getNext());
    targetFound ->getNext() ->setPrevious (targetFound ->getPrevious());
    targetFound = NULL;
    delete targetFound;
    size--;
    return tFound ;

}
Example #26
0
void DLList::popBack(){
        if(head != NULL)
                {
                if(head->getNextNode() == NULL){
                        popFront();
                }
                else{
                        DLNode* b = head;
                        DLNode* previous = b;
                        while(b->getNextNode() != NULL){
                        previous = b;
                        b = b->getNextNode();
                }
                delete b;
                previous->setNextNode(NULL);
                size--;
                }
        }
}
Example #27
0
/**
 * removes the tail node from the list,
 * or does nothing if the list is empty
 */
void DLList::popBack()
{
    if (head_ != NULL)
    {
         if (head_ == tail_)
         {
             popFront();
         } else 
         {
             DLNode* temp = head_;
             while (temp->getNext() != tail_)
             temp = temp->getNext();
             temp->setNext(NULL);
             delete tail_;
             tail_ = temp;
             size_ -= 1;
         }
    }
}
Example #28
0
//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;
}
Example #29
0
void DLList::popBack() {
    if (head != NULL){
        if (head->getNext() == NULL) {
            popFront();
        } else {
            DLNode* i = head;
            DLNode* j = NULL;
            while (i->getNext() != NULL) {
                j = i;
                i = i->getNext();
            }
            if (i != NULL) {
                delete i;
                j->setNext(NULL);
                tail = j;
            }
            count--;
        }
    }
}
Example #30
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;
    }
}