コード例 #1
0
ファイル: graph.c プロジェクト: smorad/cmps101
ListRef getPathTo(GraphRef g, int dest){
	int path = dest;
	ListRef list = newList();
	printf("Path to %d: ", dest);
	while(path!=-1){
		insertBeforeFirst(list,path);
		path = g->parent[path];
	}
	return list;
}
コード例 #2
0
ファイル: List.c プロジェクト: kevinjandres/Bookstore
// inserts a node in a list before the current node
// the new node must have a pointer next to current
// and point the previous to the previous of the current of the node
void insertBeforeCurrent(ListRef L, long data) {
    NodeType *node = malloc(sizeof(struct Node));
    node ->data = data;

    if(!offEnd(L)) {
        if(L->current!=L->first) {
            node->next = L->current;
            node->prev = L->current->prev;
            node->prev->next=node;
            L->current->prev=node;
            L->current = node;
        }
        else insertBeforeFirst(L, data);

    }

}
コード例 #3
0
ファイル: list.c プロジェクト: ishvartser/slug
/*
 * insert before the current node, if defined
 */
void insertBeforeCurrent(ListRef L, long data)
{
    NodeRef n;
    if (L == NULL) {
        printf( "Error: Called insertBeforeCurrent() on NULL ListRef\n");
        //exit(EXIT_FAILURE);
    } else if (isEmpty(L)) {
        printf( "Error: Called insertBeforeCurrent() on empty ListRef\n");
        //exit(EXIT_FAILURE);
    } else if (offEnd(L)) {
        printf("Error: Called insertBeforeCurrent() with offEnd() == true\n");
        //exit(EXIT_FAILURE);
    }
    if (atFirst(L)) {
        insertBeforeFirst(L, data);
    } else {
        n = newNode(data);
        n->next = L->current;
        n->prev = L->current->prev;
        n->prev->next = n;
        n->next->prev = n;
        L->length++;
    }
}