Beispiel #1
0
    // left is the index of the leftmost element of the array
 // right is the index of the rightmost element of the array (inclusive)
 //   number of elements in subarray: right-left+1
 int partition(char*list, int x, int left, int right, int pivotIndex) {
    int pivotValue = list[pivotIndex];
    char tempa = list[pivotIndex];
    list[pivotIndex] = list[right];
    list[right]=tempa;  // Move pivot to end
    displayList( list, x);
    delay(500);
    int storeIndex = left;
    for(int i=left;i<right;i++) {// left ≤ i < right
        if(list[i] < pivotValue) {
            char tempb=list[i];
           list[i]=list[storeIndex];
           list[storeIndex]=tempb;
            storeIndex++;
                 displayList( list, x);
                      delay(500);
        }
    }
    char tempc = list[storeIndex];
   list[storeIndex]=list[right];  // Move pivot to its final place
   list[right]=tempc;
                         displayList( list, x);
                              delay(500);
    return storeIndex;
 }
int main(){
	int x = 21;
	struct list *head = NULL;

	head = insertAtEnd(head, x);
	head = insertAtEnd(head, x);
	head = insertAtEnd(head, x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	head = insertAtEnd(head, ++x);
	displayList(head);
	
	//delete by position
	printf("Deleted Data : %d\n", deleteNodeAtPos(head, 3));
	displayList(head);

	//delete by value (all the nodes containing this value will be deleted)
	head = deleteNodesContaining(head, 25);
	head = deleteNodesContaining(head, 21);
	displayList(head);

}
void
main() {

        int dat;
        struct linkList *list1 = NULL, *list2 = NULL;

        InsertLinkedList(&list1, 21, 1);         /*Insert node in Beginning */
        InsertLinkedList(&list1, 31, 2);         /*Insert at position 2 */
        InsertLinkedList(&list1, 41, 3);
        InsertLinkedList(&list1, 51, 4);
        InsertLinkedList(&list1, 61, 5);
        InsertLinkedList(&list1, 72, 6);
        InsertLinkedList(&list1, 87, 7);

        InsertLinkedList(&list2, 91, 1);
        InsertLinkedList(&list2, 92, 2);
        InsertLinkedList(&list2, 93, 3);
        InsertLinkedList(&list2, 94, 4);
        displayList(list1);
        displayList(list2);

	/* build a Y list */
	list2->next->next->next->next = list1->next->next->next;
        displayList(list1);
        displayList(list2);

	printf ( "Intersecting node is %d\n", intersectNode(list1, list2, 7, 8));
}
Beispiel #4
0
int main() {
    ListH pHead = NULL;
    Position s = NULL;
    pHead = creatList(pHead);
    printf("你输入的链表为\n");
    int m;
    displayList(pHead);
    printf("请输入一个整数:");
    scanf("%d", &m);
    
    s = search(pHead, m);
    if (s) {
        printf("找到该元素\n");
        printf("删除前\n");
        displayList(pHead);
        printf("删除后\n");
        Delete(pHead, s);
        displayList(pHead);
    }
    else {
        printf("未找到该元素\n");
        InsertLast(m, pHead);
        printf("插入后\n");
        displayList(pHead);
    }
    
    return 0;
}
Beispiel #5
0
int test(){
    T t ;
    t.x =1;
    t.y =2;
    T t1 = {3,4};
    Find f =&find;
    ListPtr list = initList(NULL,NULL);
    insertToList(list, &t, sizeof(t));
    insertToList(list, &t1, sizeof(t1));
    int a =1; 
    void*args[0];
    args[0]=&a;

    T* s = getFromList(list,f,args);
    //printf("%d %d\n", s->y, t.y);

    insertToList(list, &t1,sizeof(t1));
    insertToList(list, &t1,sizeof(t1));
    insertToList(list, &t1,sizeof(t1));
    insertToList(list, &t1,sizeof(t1));
    insertToList(list, &t1,sizeof(t1));
    a = 1;
    T* r = getFromList(list,f,args);
    printf("%d\n", r->y);
    printf("count %d\n", getCount(list));
    displayList(list,display,4);
    printf("remove %d\n",removeFromList(list,f,args));
    displayList(list,display,4);
    r = getFromList(list,f,args);
    //printf("%d\n", r);
    assert(r==NULL);
    displayList(list,display,4);
    t1.y=10;
    a = 3;
    int count = setToList(list,&t1,sizeof(t1),f,args);
    printf("update %d\n", count);
    displayList(list,display,4);
    ListPtr ptr = list;
    int i = 0;
    do{
        void * data = NULL;
        if(i>4){
            data= preFromList(&ptr,list,f,args);
        }else{
            data = nextFromList(&ptr,list,f,args);
        }
        if(ptr != list){
            display(data,ptr->id);   
            printf("\n");
        }
        i++;
    }while(ptr!=list);
    //displayList(list,display,4);

    int num = freeList(&list);
    printf("%d\n", num);

}
Beispiel #6
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;
}
Beispiel #7
0
int main()
{
    int mid = 0;
    int Array[] = {0,1,2,3,4,1,6,1,8,1,100};
    //int Array[] = {0,2,2,3,4,1,11,1};
    printf("Initial list is : ");
    displayList(Array, 0, N);
    mid = ToW(Array, 0, N-1, 0, 0);
    printf("List one is : ");
    displayList(Array, 0, mid);
    printf("List Two is : ");
    displayList(Array, mid, N);
}
Beispiel #8
0
int main()
{
	head1 = createList();
	head2 = createList();
	printf("\nFirst list is:\n");
	displayList(head1);
	printf("\nSecond list is:\n");
	displayList(head2);
	head = addLists(head1, head2);
	printf("\nThe sum results as: \n");
	displayList(head);
	return 1;
}
int main()
{
    int arr[] = {3, 4, 5, 6, 7};
    std::vector<int> array(arr, arr+sizeof(arr)/sizeof(int));
    struct node * head = new struct node;

    createLinkedList(array, &head);
    displayList(head);
//    reverse(&head);
    reverseRecursive(&head);
    displayList(head);
    return 0;
}
Beispiel #10
0
int main()
{
    int arr[] = {3, 4, 5, 6, 7};
    std::vector<int> array(arr, arr+sizeof(arr)/sizeof(int));
    struct node * head = new struct node;

    createLinkedList(array, *head);
    displayList(head);
    reverse(head);

    std::cout<<"here"<<std::endl;
    displayList(head);
    return 0;
}  
Beispiel #11
0
int main(){
	int x = 21;
	struct list *head = NULL;

	insertAtEnd(&head, x);
	insertAtEnd(&head, ++x);
	insertAtEnd(&head, ++x);
	insertAtEnd(&head, ++x);
	insertAtEnd(&head, ++x);
	insertAtEnd(&head, ++x);

	displayList(head);
	deleteList(&head);
	displayList(head);
}
int main(int argc, char *argv[]) {
    struct ListNode* HEAD = NULL;
    displayList(HEAD);
    insertInList(&HEAD, 100, 1);
    insertInList(&HEAD, 200, 2);
    insertInList(&HEAD, 300, 3);
    insertInList(&HEAD, 400, 4);
    insertInList(&HEAD, 350, 3);
    insertInList(&HEAD, 500, 5);
    displayList(HEAD);
    reverseInPair(&HEAD);
    printf("\n");
    displayList(HEAD);
    return 0;

}
Beispiel #13
0
void Interface::menu(int& userChoice)//displays the initial menu for user
{
    cout << "Choose a number from the menu" << endl;
    cout << "-----------------------------" << endl;
    cout << "1 to add new item to database" << endl;
    cout << "2 to display all info" << endl;
    cout << "3 to arrange list" << endl;
    cout << "4 to search for a name" << endl;
    cout << "5 to quit the program" << endl;

    cin >> userChoice;
    switch (userChoice) {
    case 1:
        addNew();
        break;
    case 2:
        displayList();
        break;
    case 3:
        selectOrder();
        break;
    case 4:
        search();
        break;
    case 5:
        break;
    default:
        cout << "Wrong input";
        break;
    }
}
Beispiel #14
0
int main()
{
    int ch;
    builddefaultLinkedList();
top:
    displayLinkedListMenu();
    printf("\n Press 4 to reverse Linked List");
    scanf("%d", &ch);
    if(ch == 1)
    {
        addNode();
        goto top;
    }
    else if (ch==2)
    {
        displayList();
        goto top;
    }
    else if(ch == 3)
    {
        return 0;
    }
    else if(ch == 4)
    {
        reverse();
        goto top;
    }
    return 0;
}
Beispiel #15
0
void main()
{
	data * start1, *start2, *startUnion;
	puts("\n Enter data in first link list.");
	start1 = create();
	puts("\n Enter data in second link list.");
	start2 = create();
	
	puts("\n First List:");
	displayList(start1);
	puts("\n Second List:");
	displayList(start2);
	startUnion = getUnion(start1, start2);
	puts("\n Union:");
	displayList(startUnion);
	getch();
}
Beispiel #16
0
int XSYNCZIP_diplaySummary(XDRM_CTRL_CONTEXT_PTR pCtx )
{
   int retval =-1;
   if ( NULL != pCtx->pZipFile )
      retval = displayList ( pCtx->pZipFile );

   return retval;
}
Beispiel #17
0
void
ClosedKnot::draw(Position where, GLfloat angle) const
{
    glPushMatrix();
    {
        glTranslatef(where.x, where.y, 0.0);
        glRotatef(angle * 180.0 / M_PI, 0.0, 0.0, 1.0);
        glCallList(displayList());
    }
    glPopMatrix();
}
int main()
{
	int data;
	head = createList();
	printf("Enter node value to add: ");
	scanf("%d", &data);
	head = addNode1(head, data);
	printf("\nThe resultant circular linked list is: \n");
	displayList(head);
	return 1;
}
Beispiel #19
0
void
main() {

        int dat;
        struct linkList *list1 = NULL;

        InsertLinkedList(&list1, 21, 1);         /*Insert node in Beginning */
        InsertLinkedList(&list1, 31, 2);         /*Insert at position 2 */
        InsertLinkedList(&list1, 41, 3);
        InsertLinkedList(&list1, 51, 4);
        InsertLinkedList(&list1, 61, 5);
        InsertLinkedList(&list1, 72, 6);
        InsertLinkedList(&list1, 87, 7);

        displayList(list1);

	printf ( "Mid node of list is %d\n", midNode(list1));
        displayList(list1);

}
BabelWindow::BabelWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::BabelWindow)
{
	ui->setupUi(this);
	hideContent();
	displayList();
	this->ui->textEdit_seeMessage->setDisabled(true);
	this->ui->lineEdit_password->setEchoMode(QLineEdit::Password);
	this->ui->lineEdit_passwordregister->setEchoMode(QLineEdit::Password);
	this->ui->lineEdit_passwordconfirmregister->setEchoMode(QLineEdit::Password);
}
Beispiel #21
0
void TestModel::getAllDisplays()
{		
	QList<GDisplay *> displayList(pModel->GetAllDisplays());	
	QList<GDisplay *>::iterator i = displayList.begin();
	
	GDisplay* aux;
	while (i != displayList.end())
	{ 
		aux = *i;
		QVERIFY( aux != NULL && aux->GetNumber() >= 1 && aux->GetNumber() <= 3 );
		++i;
	}
}
Beispiel #22
0
int runInterpreter(void)
{
	AST M = getTree("main");
	if(M != NULL) 
	{
		AST R = simplify(M);
		if((R->kind == ACTION_NK) ||
		   ((R->kind == BASIC_FUNC_NK) &&
		   	((R->extra == PRILST_FK) ||
			(R->extra == PRINT_FK) ||
			(R->extra == PROD_FK) ||
			(R->extra == READI_FK) ||
			(R->extra == READC_FK))))
		{
			AST ret = performAction(R);
			if(ret->kind != EMPTYLIST)
			{
				if(ret->kind == CONS_NK)
					displayList(ret);
				else
					displayAST(ret);
			}
		} 
		else
		{
			AST S = simplify(R);
			if(S->kind != EMPTYLIST)
			{
				if(S->kind == CONS_NK)
					displayList(S);
				else
					displayAST(R);
			}
		}
		printf("\n");
	}
	return 0;
}	
Beispiel #23
0
void displayList(AST r)
{
	if(r->kind == EMPTYLIST)
	{
		printf("[]");
		return;
	}
	else
	{
		printValue(simplify(r->fields.subtrees.s1));
		printf(":");
		displayList(simplify(r->fields.subtrees.s2));
		return;
	}
}
Beispiel #24
0
int main()
{
    struct NODE *header;
    header = NULL;
    int i;

    for(i=0; i<MAX_NODE; i++)
        addNode(&header,((rand()%25)+(rand()%25)));
    displayList(header);

    delNode(&header,19);
    displayList(header);

    delNode(&header,0);
    displayList(header);

    delNode(&header,28);
    displayList(header);

    delNode(&header,16);
    displayList(header);

    return(1);
}
Beispiel #25
0
int MyLIst::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: addElement((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: remove(); break;
        case 2: displayList(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
void main(){

	int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	struct node* list = createList(arr,9);

	printf("Given List: ");
	displayList(list);

	int mid = medianList2(list);
	if (mid == INT_MIN)
		printf("Empty\n");
	else
		printf("Median of the List is %d\n", mid);

	getchar();
}
Beispiel #27
0
int main()
{
   int num;
   int grp;

   struct NODE *head;

   for(num=1; num<101; num++)
   {
      grp = getGrp(num);
//      printf("Number [%d] goes to group [%d]\n",num,grp);
addNode(&head,grp,num);
   }
displayList(head);

   return 1;
}
Beispiel #28
0
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	
	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(width, height);
	glutCreateWindow("quadview");
	
	glutKeyboardFunc(keyboard);
	glutReshapeFunc(reshape);
	glutDisplayFunc(display4);
	glutMotionFunc(motion);
	glutMouseFunc(mouse);

	init();
	torus_list=displayList();

	glutMainLoop();

	return 0;
}
Beispiel #29
0
void ProcList::OnSort(wxListEvent& event)
{
	SetSortImage(columns[sort_column].listctrl_column, SORT_NONE);

	int new_column = 0;
	for (int n=0;n<MAX_COLUMNS;n++)
		if (columns[n].listctrl_column == event.m_col)
			new_column = n;

	if (sort_column == new_column)
	{
		// toggle if we clicked on the same column as last time
		sort_dir = (SortType)((SORT_UP+SORT_DOWN) - sort_dir);
	} else {
		// if switching columns, start with the default sort for that column type
		sort_column = new_column;
		sort_dir = columns[sort_column].default_sort;
	}

	SetSortImage(columns[sort_column].listctrl_column, sort_dir);

	sortList();
	displayList();
}
Beispiel #30
0
void ProcList::showList(const Database::List &list)
{
	this->list = list;
	sortList();
	displayList();
}