Пример #1
0
//输入的链表只有两个结点
void test2()
{
	SinglyListNode* pNode1 = createListNode(1);
	SinglyListNode* pNode2 = createListNode(2);

	connectListNode(pNode1, pNode2);

	test("test2", pNode1);
}
int main() {
    Solution sln;
    ListNode* n1 = createListNode(vector<int>({1, 2, 3, 3, 4, 4, 5}));
    n1 = sln.deleteDuplicates(n1);
    printListNode(n1);

    n1 = createListNode(vector<int>({1, 1, 1, 2, 3}));
    n1 = sln.deleteDuplicates(n1);
    printListNode(n1);

    n1 = createListNode(vector<int>({1, 1, 1}));
    n1 = sln.deleteDuplicates(n1);
    printListNode(n1);
    return 0;
}
Пример #3
0
SE_Result SE_List_AddBefore(SE_List* list, int index, SE_Element e)
{
    SE_ListNode* ln;
	SE_ListNode* p;
	SE_ListNode* prev;
	int i;
    SE_ASSERT(list);
    SE_ASSERT(list->head != NULL);
    SE_ASSERT(list->tail != NULL);
    SE_ASSERT(index >= 0 && index < list->size);
    if(index < 0 || index >= list->size)
        return SE_INVALID;
    ln = createListNode(e);
    if(ln == NULL)
        return SE_INVALID;
    p = list->head;
    for(i = 0 ; i <= index ; i++)
    {
        p = p->next;
    }
    SE_ASSERT(p != NULL);
    prev = p->prev;
    prev->next = ln;
    ln->next = p;
    ln->prev = prev;
    p->prev = ln;
    list->size++;
    return SE_VALID;
}
Пример #4
0
list* addRowToTable(list* row, list* table){
	list* tableDown=table->down;
	if(tableDown==NULL){
		tableDown= (list*) malloc(sizeof(list));
		table->down= tableDown;
	}
	list* searchNode=searchRight(row->nodeName, tableDown);
	if(searchNode==NULL){

		list* newNode=createListNode(row->nodeName);
		copyAttributes(newNode,row->attrList);
		addRight(newNode, tableDown);
		
		list*rowColumns= row->down;
		if(rowColumns==NULL || rowColumns->right==NULL){
			yyerror("ERROR\n");
		}
		rowColumns= rowColumns->right;
		while(rowColumns !=NULL){
			addColumnToRow(rowColumns, newNode);
			rowColumns= rowColumns->right;
		}
	}else{
		yyerror("ERROR\n");
	}
}
Пример #5
0
 void test() {
     vector<string> v = { "14623", "14627", "1462350", "1452360" };
     for (string s : v) {
         ListNode *head = createListNode(s);
         out(head);
         ListNode dummy(-1);
         dummy.next = head;
         ListNode *result = merge(&dummy, 6);
         out(dummy.next);
         out(result);
     }
     for (string s : v) {
         ListNode *head = createListNode(s);
         out(head);
         ListNode *result = sortList(head);
         out(result);
     }
 }
Пример #6
0
// Add data to the END of the list
void appendTo(List *list, void *data) {
	ListNode *new_node = createListNode(data);
	if (list->head == NULL) {
		list->head = new_node;
	} else {
		list->tail->next = new_node;
		new_node->prev = list->tail;
	}
	list->tail = new_node;
	list->num_nodes++;
}
Пример #7
0
// Turns a Tree into a List in sorted order.
//
// INPUT: root - The root of a Tree which will be flattened.
// OUTPUT: Returns a pointer to the head of a list, which contains
//         the values of the tree in sorted order.
//
// NOTE: You should not be performing any actual "sorting" aside from
//       taking advantage of the order of the tree. Do not add the nodes
//       from the tree to the list in some random order and then sort the
//       list.
List* flattenTreeToList(Tree* root)
{
    static List newList;
    static List* head = &newList;
    if(root != NULL)
    {
        flattenTreeToList(root->left);
        head->next = createListNode(root->data);
        head = head->next;
        flattenTreeToList(root->right);
    }
    return newList.next;
}
Пример #8
0
SE_Result SE_List_AddLast(SE_List* list, SE_Element e)
{
	SE_ListNode* ln;
    SE_ASSERT(list);
    SE_ASSERT(list->head != NULL);
    SE_ASSERT(list->tail != NULL);
    ln = createListNode(e);
    if(ln == NULL)
        return SE_INVALID;
    list->tail->next = ln;
    ln->prev = list->tail;
    list->tail = ln;
    list->size++;
    return SE_VALID;
}
Пример #9
0
list* addTableToColumn(list* table, list* column){
	if(table!=NULL){
		list* newNode= createListNode(table->nodeName);
		copyAttributes(newNode, table->attrList);
		column->down= newNode;
		if(table->down ==NULL || table->down->right==NULL)
			yyerror("ERROR\n");

		list* tableRows= table->down->right;
		while(tableRows!=NULL){
			addRowToTable(tableRows, newNode);
			tableRows= tableRows->right;
		}
	}
}
Пример #10
0
//k为负值
void test4()
{
	SinglyListNode* pNode1 = createListNode(1);
	SinglyListNode* pNode2 = createListNode(2);
	SinglyListNode* pNode3 = createListNode(3);
	SinglyListNode* pNode4 = createListNode(4);
	SinglyListNode* pNode5 = createListNode(5);
	SinglyListNode* pNode6 = createListNode(6);

	connectListNode(pNode1, pNode2);
	connectListNode(pNode2, pNode3);
	connectListNode(pNode3, pNode4);
	connectListNode(pNode4, pNode5);
	connectListNode(pNode5, pNode6);

	test("test4", pNode1, -3);
}
Пример #11
0
list* addColumnToRow(list* column, list* row){
	list* rowDown= row->down;
	if(rowDown==NULL){
		rowDown= (list*)malloc(sizeof(list));
		row->down= rowDown;
	}

	list* searchNode= searchRight(column->nodeName, rowDown);
	if(searchNode==NULL){
		list* newNode= createListNode(column->nodeName);
		copyAttributes(newNode, column->attrList);
		if(column->text!=NULL && column->down!=NULL){
			yyerror("ERROR\n");
		}
		else if(column->text!=NULL)
			newNode->text= strdup(column->text);
		
		addRight(newNode, rowDown);
		if(column->down!=NULL)
			addTableToColumn(column->down, newNode);
	}else
		yyerror("ERROR\n");
}
Пример #12
0
int main()
{
	List l;

	//createListNoNodes(&l); // working

	Info data1;
	data1.firstName = "felipe";
	data1.lastName = "Cantagalli";
	data1.puid = 27296830;
	data1.age = 22;

	Info data2;
	data2.firstName = "bibi";
	data2.lastName = "letti";
	data2.puid = 12345678;
	data2.age = 20;

	Info data3;
	data3.firstName = "ricardo";
	data3.lastName = "cantagalli";
	data3.puid = 87654321;
	data3.age = 50;

	Info data4;
	data4.firstName = "suzete";
	data4.lastName = "tozato";
	data4.puid = 43256789;
	data4.age = 48;

	createListNode(&l,data1); // working

	printList(&l);

	insertFront(&l, data2); // working
	//insertFront(&l,data3);
	//insertFront(&l,data4);
	printList(&l);
	//insertEnd(&l, data2); //working
	insertEnd(&l,data3);
	insertFront(&l,data4);
	printList(&l);

	//insertMiddle(&l,data4,1); //working

	//deleteFront(&l); // working
	//deleteFront(&l);

	//deleteEnd(&l);
	//deleteEnd(&l);

	deleteMiddle(&l,1); // wroking
	//deleteMiddle(&l,1);

	printList(&l);


	//Node* n = lookUpByIndex(&l,1);
	//printf(" %s\n",n->data.firstName);
	//n = lookUpByIndex(&l,0);
	//printf(" %s\n",n->data.firstName);

	int aux = traverse(&l,27296831);
	//printf("funcionou ?! : %d",aux);

	return 0;
}
Пример #13
0
//输入的链表只有一个结点
void test3()
{
	SinglyListNode* pNode1 = createListNode(1);

	test("test3", pNode1);
}