Пример #1
0
double *getNewValues(double *x, int n, list *blocks, double *y)
{
    int i=0, j;
    list *node = blocks;
    while(i<n)
    {
        if(node != NULL && checkBoundires(node, i))
        {
            for(j=i;j<=node->blockEndIndex;j++)
                y[j] = node->avg;
            
            i = node->blockEndIndex+1;
            node = node->next;
        }
        else
        {
            y[i] = x[i];
            i++;
        }
    }
    
    
    deleteList(blocks);
    
    return y;
}
Пример #2
0
 static void deleteList(ListNode * l)
 {
     if(! l -> next)
         delete l;
     deleteList(l -> next);
     delete l;
 }
Пример #3
0
int main() {
    linknode *flist,*rlist,*find;
    int index; char value;
    rlist=(linknode*)malloc(sizeof(linknode));
    rlist->next=NULL;
    printf("plase input a sting,end with the KEY_Enter \n");
    //flist=CreateListF();
    //printLinkList(flist);
    CreateListR(rlist);
    printLinkList(rlist);
    printf("list length=%d \n",getLength(rlist));
    printf("set insert node:index,value:");
    scanf("%d,%c",&index,&value);
    printf("insert a element!");
    insertList(rlist,value,index);
    printLinkList(rlist);
    printf("list length=%d \n",getLength(rlist));
    printf("set delete node index:");
    scanf("%d",&index);
    deleteList(rlist,index);
    printf("delete a element!");
    printLinkList(rlist);
    printf("list length=%d \n",getLength(rlist));
    printf("set visit node index:");
    scanf("%d",&index);
    find=getNode(rlist,index);
    if(find!=NULL)
    {
        printf("this node value=%c \n",find->data);
    }
    
    return 0;
}
Пример #4
0
void AppleMacIO::publishBelow( IORegistryEntry * root )
{
    OSCollectionIterator *	kids;
    IORegistryEntry *		next;
    IOService *			nub;

    // infanticide
    kids = IODTFindMatchingEntries( root, kIODTRecursive, deleteList() );
    if( kids) {
	while( (next = (IORegistryEntry *)kids->getNextObject())) {
	    next->detachAll( gIODTPlane);
	}
	kids->release();
    }

    // publish everything below, minus excludeList
    kids = IODTFindMatchingEntries( root, kIODTRecursive | kIODTExclusive,
					excludeList());
    if( kids) {
	while( (next = (IORegistryEntry *)kids->getNextObject())) {

            if( 0 == (nub = createNub( next )))
                continue;

            nub->attach( this );
	    
	    processNub(nub);
	    
            nub->registerService();
        }
	kids->release();
    }
}
Пример #5
0
//
// tries to make an exit parse var
PARSE_VAR *use_one_parse_token_exit(CHAR_DATA *looker, PARSE_TOKEN *tok, 
				    const char *name) {
  int    type = FOUND_NONE;
  void *found = find_specific(looker, name, "", "", FIND_TYPE_EXIT, tok->scope,
			      tok->all_ok, &type);

  // make sure we found something
  if(found == NULL)
    return NULL;
  else {
    PARSE_VAR *var = newParseVar(PARSE_VAR_EXIT);

    // if multiple vals were possible, flag it
    var->multiple_possible = tok->all_ok;

    // Is it a single exit?
    if(type == FOUND_EXIT)
      var->ptr_val = found;

    // or is it multiple exits?
    else if(type == FOUND_LIST) {
      if(listSize(found) > 1) {
	var->ptr_val = found;
	var->multiple = TRUE;
      }
      else if(listSize(found) == 1) {
	var->ptr_val = listPop(found);
	deleteList(found);
      }
      else {
	deleteList(found);
	deleteParseVar(var);
	var = NULL;
      }
    }

    // We should never reach this case
    else {
      deleteParseVar(var);
      var = NULL;
    }

    // return whatever we found
    return var;
  }
}
Пример #6
0
/***********************************************************************
     * ExchangeWindow
     * init

***********************************************************************/
void fired::ExchangeWindow::init(fired::MapObjectCollector *collector) {
	deleteList(exchange);
	sf::Vector2f winOffset = win->offset;

	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 5; j++)
			exchange.push_back(new fired::InventoryWindowItem(winOffset + sf::Vector2f(380.0f + 35.0f * i, 185.0f + 35.0f * j), &collector->items[i][j], itAny));
}
Пример #7
0
// This destructor destroys a list and frees the associated nodes.
void deleteList(List l)
{
    if (l == 0)
		return;
    List rest = l->nextPtr;
	free(l);
	deleteList(rest);
};
Пример #8
0
void deleteList(struct xTEDSQualifierListNode* p)
{
	if(p==NULL) return;
	deleteList(p->next);
	if(p->data!=NULL)
		delete(p->data);
	free(p);
}
void deleteList(Node *head)
{
	if(!head)
		return ;

	deleteList(head->next) ;
	free(head) ;
}
Пример #10
0
int _tmain(int argc, _TCHAR* argv[])
{
	printf("0 - exit\n");
    printf("1 - add value to sorted list\n");
    printf("2 - remove value from list\n");
    printf("3 - print list\n");

	IntList *head = newList(-1);

	while(true)
	{
		printf("Input command:\n");
		int command = 0;
		scanf("%d", &command);
		int val = 0;
		switch (command)
		{
			case 0:
				deleteList(head);
				return 0;
			case 1:
				printf("Input value:\n");
				
				scanf("%d", &val);
				addToSortedList(head, val);
				break;
			case 2:
				printf("Input value:\n");
				
				scanf("%d", &val);
				removeValue(head, val);
				break;
			case 3:
				printList(head);
				break;
		};

	}
	
	deleteList(head);

	scanf("%*s");
	return 0;
}
int main()
{
    constexpr unsigned N = 5;
    list listx = nullptr;

    createCircularList(listx,N);
    printList(listx);
    deleteList(listx);
    return 0;
}
Пример #12
0
/* deletes list */
void deleteList(element head,int is_nodes,int recursivly){
	if(head==NULL){
		return;
	}
	deleteList(head->next,is_nodes,recursivly);
	if (recursivly==1){
		remove_tree(head->node,0,recursivly);
	}
	free(head);
}
Пример #13
0
void destroyHashTable(hash_t *hashTable) {
   // Free all of the lists
   for (int i = 0; i < hashTable->capacity; i++) {
        if (hashTable->buckets[i] != NULL) {
            deleteList(hashTable->buckets[i]);
        }
   }
   free(hashTable->buckets);
   free(hashTable);
}
Пример #14
0
/// Function name  : deleteScriptGenerator
// Description     : Destroys a ScriptGenerator
// 
// SCRIPT_GENERATOR*  &ScriptGenerator   : [in] ScriptGenerator to destroy
// 
VOID  deleteScriptGenerator(SCRIPT_GENERATOR*  &pGenerator)
{
   // Delete Arguments/Variables list
   deleteList(pGenerator->pVariablesList);

   // Delete XML Tree
   if (pGenerator->pXMLTree)
      deleteXMLTree(pGenerator->pXMLTree);

   // Zero Layout
   utilZeroObject(&pGenerator->oLayout, XML_SCRIPT_LAYOUT);

   // Delete INPUT and OUTPUT
   deleteList(pGenerator->pInputList);
   deleteCommandStream(pGenerator->pOutputStream);
   
   // Delete Generator
   utilDeleteObject(pGenerator);
}
Пример #15
0
List& List::operator =(
		const List& other) {

	if (this != &other) {
		deleteList();
		copyList(other);
	}

	return *this;
}
Пример #16
0
void deleteHashSet(struct HashSet *hashset)
{
	int index;

	for (index = 0; index < hashset->numberBuckets; index++)
		deleteList(hashset->buckets[index]);

	free(hashset->buckets);
	free(hashset);
}
Пример #17
0
void main()

{

	node *head,*tail;

	createList(&head);

	insertAtBeginning(&head,4);

	insertAtBeginning(&head,3);

	insertAtBeginning(&head,2);

	insertAtBeginning(&head,5);

	insertAtBeginning(&head,6);

	insertAtBeginning(&head,10);

	insertAtEnd(&head,1);

    insertInBetween(&head,9,2);

    traverseList(head);

    printf("\n");

    reverseTraversal(head);

    reverseList(&head);

    traverseList(head);

    deleteEnd(&head);

    traverseList(head);

    deleteBeginning(&head);

    traverseList(head);

    deleteAfter(&head,2);

    traverseList(head);

    deleteList(&head);

    traverseList(head);

//	tail= getTail(head);

//	printf("\nTail= %d",tail->info);

}
Пример #18
0
int main() {
	int data1,data2,data3,data4,data5;
	int nonData = 6;
	int * pFind = NULL;
	List test = NULL;
	initList(&test);

	data1 = 10;data2 = 20;data3 = 30;data4 = 40;data5 = 50;
	addToList(test, (void*)&data1);
	addToList(test, (void*)&data2);
	addToList(test, (void*)&data3);
	addToList(test, (void*)&data4);
	addToList(test, (void*)&data5);
	displayList(test);

	printf("%s","Searching for 30");
	pFind = (int*)findInList(test, (void*)&data3, intGreater);

	if (pFind)
	{
		printf("%s%d","\nFound data value: ", *pFind);
	}
	else {
		printf("%s","\nData not found");
	}

	printf("%s","\nSearching for 99 (shouldn't be in list)");
	pFind = (int*)findInList(test, (void*)&nonData, intGreater);

	if (pFind)
	{
		printf("%s%d","\nFound data value: ", *pFind);
	}
	else {
		printf("%s","\nData not found");
	}

	printf("%s","\nremoving one item then displaying\n");
	removeFirst(test);
	displayList(test);

	printf("%s","removing all items then displaying\n");
	deleteList(test);
	displayList(test);

	printf("%s","Attempting to remove from an empty list\n");
	removeFirst(test);
	displayList(test);

	cleanupList(&test);

	printf("%s","All tests complete\n");

	return 0;
}
Пример #19
0
List* merge(List* newList1, List* newList2)
{
	Position head1 = first(newList1);
	Position head2 = first(newList2);
	List* newList = createList();
	while (head1 != NULL && head2 != NULL)
	{
		if (retrieve(head1, newList1) <= retrieve(head2, newList2))
		{
			add(newList, retrieve(head1, newList1));
			head1 = next(head1, newList1);
		}
		else
		{
			add(newList, retrieve(head2, newList2));
			head2 = next(head2, newList2);
		}
	}
	if (head2 == NULL)
		while (head1 != NULL)
		{
			add(newList, retrieve(head1, newList1));
			head1 = next(head1, newList1);
		}
	if (head1 == NULL)
		while (head2 != NULL)
		{
			add(newList, retrieve(head2, newList2));
			head2 = next(head2, newList2);
		}
	deleteList(newList1);
	deleteList(newList2);
	List* newNewList = createList();
	head1 = first(newList);
	while (head1 != NULL)
	{
		add(newNewList, retrieve(head1, newList));
		head1 = next(head1, newList);
	}
	deleteList(newList);
	return newNewList;
}
Пример #20
0
	void deleteHashTable(HashTable &hashT)
	{
		for (int i = 0; i < hashT.size; ++i)
		{
		//	cout << "deleted list ";
		//	printList(hashT.arr[i]);
		//	cout << "\n";
			deleteList(hashT.arr[i]);
		}
		delete[] hashT.arr;
	}
Пример #21
0
void LinkedList<T>::initList(const T& component )
{
    if(head != nullptr)
    {
        deleteList();
    }
    addToFront(component);

    head->next = nullptr;
    tail = head;
}
Пример #22
0
ossimImageChain::~ossimImageChain()
{
   removeListener((ossimConnectableObjectListener*)this);
   deleteList();

   if(theChildListener)
   {
      delete theChildListener;
      theChildListener = NULL;
   }
}
Пример #23
0
int main()
{
    Node *l = insertFront(0, NULL);
    for (int i = 1; i < 10; ++i) {
        l = insertFront(i, l);
    }
    printList(l);
    l = reverseList(l);
    printList(l);
    deleteList(l);
}
Пример #24
0
 /* Does: Assignment Operator
  * Arguments: 
  * Returns: 
  * Calls: SortedList::deleteList, SortedList::insertNodesFromList
  * Notes: This is not a constructor - a SortedList has already been
  *  made when you call this.  So, no need to set head to NULL here.
  *  In fact, that would be a mistake if head was pointing to a node.
  */
const SortedList& SortedList::operator=(const SortedList &rhs){	
//check to make sure that you don't overwrite yourself
//with yourself...just in case someone does list1 = list1;
  
  if (this != &rhs) {
	  deleteList();
	  copyNodesFromList(rhs.head);    
  }
  
    //unlike copy constructor, return this (a pointer to yourself)
  return *this;
}
Пример #25
0
/*  Print the list

    param:  heap    pointer to the list
    pre:    the list is not empty
    post:   The tasks from the list are printed out in priority order.
			The tasks are not removed from the list.
*/
void printList(DynArr *heap)
{
    /* FIXME: Write this */
    struct DynArr *toPrint = createDynArr(sizeDynArr(heap));
    copyDynArr(heap, toPrint);
    int i, max = sizeDynArr(toPrint);
    sortHeap(toPrint);
    // call print_type() on each node
    for(i = 0; i < max; i++)
        print_type(getDynArr(toPrint, i));
        deleteList(toPrint);
}
Пример #26
0
int main()
{
	dlinklist *head;
	int num;
	printf("please input node num\n");
	scanf("%d", &num);
	head = createList(num);
	printList(head);
	printList(insertList(head, 2));
	printList(deleteList(head, 2));	
	return 0;
}
Пример #27
0
TEST(Leet, Basic02){
    ListNode* pRoot = new ListNode(3);
    ListNode* pCurr = pRoot;
    pCurr->next = new ListNode(2);
    pCurr = pCurr->next;
    pCurr->next = new ListNode(4);

    Solution sol;
    ListNode* pSorted = sol.sortList(pRoot);

    ASSERT_TRUE(validateSortedList(pSorted));
    deleteList(pSorted);
}
Пример #28
0
void deleteHash(Hashtable **hashtable_ptr, deleter delete_fn) {
	//free the memory associated with hash
	if ((hashtable_ptr != NULL) && (*hashtable_ptr != NULL)) {
		Hashtable *hash_table = *hashtable_ptr;
		for(int i = 0; i < hash_table->num_buckets; i++) {
			deleteList(&hash_table->buckets[i], delete_fn);
		}
		free(hash_table->buckets);
		free(hash_table);
		*hashtable_ptr = NULL;
	}
	
}
Пример #29
0
int ShapeHandler::saveFile(const std::string & fileName)
{
	std::ofstream file(fileName, std::ios::out | std::ios::trunc);

	if(file)
	{
		file << list();
		file << deleteList();
		file.close();
		return 0;
	}
		return UNKNOWN_FILE_ERROR;
}
Пример #30
0
/// Function name  : deleteDocumentsControlData
// Description     : Destroys documents control data
// 
// DOCUMENTS_DATA*  &pDocumentsData   : [in] Documents data
// 
VOID  deleteDocumentsControlData(DOCUMENTS_DATA*  &pDocumentsData)
{
   
   // Delete Documents list
   deleteList(pDocumentsData->pDocumentList);

   // Destroy ImageList and title font
   ImageList_Destroy(pDocumentsData->hImageList);
   DeleteFont(pDocumentsData->hTitleFont);

   // Delete calling object
   utilDeleteObject(pDocumentsData);

   }