Пример #1
0
int main(void)
{
  char command;
  NodePointer list = NULL;
  
  printf("Online Bookstore Inventory Management Program.\n\nCommands are I (insert), D (delete), S (search by name),\n  V (search by rating), P (print), Q (quit).\n");
  
  
  do
  {
    printf("\nCommand?: ");
    scanf(" %c",&command);
    if(command >= 'a' && command <= 'z')
       command = command - 'a' + 'A';
    if(command == 'I')
      list = insert(list);
    else if(command == 'D')
      list = deletion(list);
    else if(command == 'S')
      search(list);
    else if(command == 'V')
      rate(list);
    else if(command == 'P')
      printlist(list);
    else if(command == 'Q')
      {
        list = quit(list);
        printlist(list);
        return 0;
      }
    else
      printf("Command invalid\n");
  }while(1);
  return 0;
}
Пример #2
0
int main()
{
	node* head = NULL;
	int numtoinsert;

	push(&head,3);
	push(&head,99);
	push(&head,32);
	push(&head,13);
	push(&head,30);

	printf("before inserting....\n");
	printlist(head);

	printf("Enter number where you want to insert\n");
	scanf("%d",&numtoinsert);

	insert(&head,numtoinsert);

	printf("after inserting\n");
	printlist(head);


	return 0;
}
Пример #3
0
Файл: main.c Проект: Rubusch/c
/*
  application's main
//*/
int main()
{
  element_t* first = NULL;
  element_t* last = first;
  global_list_size = 0;

  // alloc
  puts("alloc");
  alloclist((void*) &first, (void*) &last);
  printf("\n");

  // output
  puts("elements - before");
  printlist(first);
  printf("\n");

  puts("sorting");
  sort((void*) &first);
  printf("\n");

  puts("elements - after");
  printlist(first);
  printf("\n");

  // free
  puts("free");
  freelist((void*) &first);
  printf("\n");

  // exit
  puts("READY.");
  exit(EXIT_SUCCESS);
}
Пример #4
0
int main()
{
    int *nums1,*nums2;
    int m,n;
    m=1;
    n=6;
    nums1=(int *)malloc(sizeof(int) * (m+n));
    nums2=(int *)malloc(sizeof(int) * n);

    for(int i=0;i<m;i++)
    {
        *(nums1+i)=(i+2)*10;
    }
    for(int i=0;i<n;i++)
    {
        *(nums2+i)=(i+3)*10+5;
    }


    printf("array 1 is :");
    printlist(nums1,m);
    printf("array 2 is :");
    printlist(nums2,n);
    merge(nums1,m,nums2,n);

    printf("last is :");
    for(int i=0;i<m+n;i++)
    {
        printf("%d,",*(nums1+i));
    }
    printf("\n");
}
Пример #5
0
void testreversealternatenodes()
{
	struct node* node = buildlistinsortedorder(10);
	printlist(node, "node");
	node = reversealternateknodes(node, 3);
	printlist(node, "node after alternate reverse by k");
}
Пример #6
0
void testrevbygivensize()
{
	struct node* node = buildlistinsortedorder(10);
	printlist(node, "node");
	node = reversebyknodes(node, 1);
	printlist(node, "after reversing by given size");
}
Пример #7
0
void testdeletealternatenodes()
{
	struct node* node = buildlistattailbyref(10);
	printlist(node, "node");
	deletealternatenodes(node);
	printlist(node, "node after deleting alternate nodes");
}
Пример #8
0
int main()
{
    struct ListNode *p1,*p2,*head;
    for(int i=0;i<2;i++)
    {
        if(i ==0)
        {
            p1=(struct ListNode *)malloc(sizeof(struct ListNode));
            p1->val=i;
            p1->next=NULL;
            head=p1;
        }
        else
        {
            p2=(struct ListNode *)malloc(sizeof(struct ListNode));
            p2->val=i;
            p2->next=NULL;
            p1->next=p2;
            p1=p1->next;
        }
    }
    printf("origin:");
    printlist(head);
    p2=reverseList(head);
    printf("after:");
    printlist(p2);
}
Пример #9
0
int main(int argc, char** argv)
{	
	int i;
 	int sz = atoi(argv[1]);
 	int element = atoi(argv[2]);
 	srand( (unsigned)time( NULL ));

	IntVectorPtr vector = VecNew(initialCapacity);

	for(i=0;i<sz+1;i++)
		vector = VecAdd(vector,rand()%100);

	printlist(vector, sz);

	if (argc == 3)
	{	
		VecQuickSort(vector);
		printf("\nThe position of the number %d is %d\n", element, VecBinarySearch(vector, element));
	} else if ( strcmp(argv[3], "-l") == 0 )
	{
		VecQuickSort2(vector, 1, sz-1);
		printf("\nThe position of the number %d is %d\n", element, VecBinarySearch2(vector->data, 0, sz, element));	
	}
		
		
	printlist(vector, sz);

	VecDelete(vector);
	return 0;
}
Пример #10
0
int main(void){
	struct node* head;
	struct node* second;
	struct node* end;

	head=malloc(sizeof(struct node));
	second=malloc(sizeof(struct node));
	end=malloc(sizeof(struct node));
	
	head->data=1;
	head->next=second;

	second->data=2;
	second->next=end;

	end->data=3;
	end->next=NULL;

	printlist(head);

	printf("delete test\n");
	if(delete_key(head,5)){
		printf("no match with key found. nothing is deleted\n");
	}
	printlist(head);

	return 0;
}
Пример #11
0
void main()
{ slink *head;
int n,x,i,j;
printf("请输入元素个数");
scanf("%d",&n);
head=creslink(n);
printf("\n");
printlist(head);
printf("\n");
printf("请输入插入的数据元素的值");
scanf("%d",&x);
printf("请输入要在哪个位序之前插入");
scanf("%d",&i);
insert(head, i,x);/*在单链表第i个元素前插入x*/
printf("\n");
printlist(head);/*输出单链表中结点的元素值*/
printf("请输入删除的数据元素的位序");
scanf("%d",&i);
j=Delete(head,i, &x);
printf("\n");
if(j)printf("%d",x);/*删除成功,则输出被删除结点的元素值*/
printf("\n"); 
printf("最终的链表变成:");
printlist(head);/*输出单链表中结点的元素值*/
turn(head);
printf("原地逆转后的链表变成:");
printlist(head);/*输出单链表中结点的元素值*/
}
Пример #12
0
int main()
{
	char ch[10],num[5];
	LinkList head;
	head=CreatList();
	printlist(head);
	printf(" Delete node (y/n):");
	scanf("%s",num);
	if(strcmp(num,"y")==0||strcmp(num,"Y")==0) 
	{
		printf("Please input Delete_data:");
		scanf("%s",ch);
		DeleteList(head,ch);
		printlist(head);
	}
	printf("Add node ? (y/n): ");
	scanf("%s",ch);
	if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
	{
		head=AddNode(head);
	}
	printlist(head);
	system("pause");
	DeleteAll(head);
}
Пример #13
0
int main(int argc, const char * argv[]){
    int d[8]={4,3,6,2,1,5};
	
	printlist(d,6);
	
	// Insert_Sort_Better(d,6);
	// printlist(d,6);

	// Insert_Shell_Sort(d,6);
	// printlist(d,6);

	// Bubble_Sort(d,6);
	// printlist(d,6);

	// Bubble_Sort2(d,6);
	// printlist(d,6);

	// MergeSort(d,6);
	// printlist(d,6);
	
	// Quick_Sort(d,0,5);
// 	printlist(d,6);
	
	// Select_Sort(d,6);
	// printlist(d,6);
	
	MakeMinHeap(d,6);
	MinheapsortTodescendarray(d,6);
	printlist(d,6);
}
Пример #14
0
void testrevrecur()
{
	struct node* node = buildlistinsortedorder(10);
	printlist(node, "node");
	revrecur(&node);
	printlist(node, "after reversing");
}
Пример #15
0
void testmergesort()
{
	struct node* node = buildlistattailbyref(20);
	printlist(node, "node before sorting");
	mergesort(&node);
	printlist(node, "node after sorting");
}
Пример #16
0
int main(void) {
    printf("starting\n");

    struct node* head;
    head=malloc(sizeof(struct node));
    head->data=0;
    head->next=NULL;

    int i;
    for(i=0; i<10; i++) {
        printf("i: %d\n",i);
        addnode(head,i+1);
    }
    printf("starting printlist\n");
    printlist(head);

    int index_fromend=3;
    struct node* rec_ptr=Nthfromend(head,index_fromend);
    if(rec_ptr!=NULL) {
        printf("%dth data from end: %d\n",index_fromend,rec_ptr->data);
    }


    for(i=0; i<10; i++) {
        random_addnode(head);
    }

    printlist(head);



    return 0;

}
Пример #17
0
void testrotate()
{
	struct node* node = buildlistinsortedorder(10);
	printlist(node, "node");
	RightRotate(&node, 2);
	printlist(node, "node after rotating");

}
Пример #18
0
void testinsertsort()
{
	struct node* node = NULL;
	node = buildlistattailbyref(10);
	printlist(node, "before sorting the list");
	insertsort(&node);
	printlist(node, "after sorting the list ");
}
Пример #19
0
void testinsertnth()
{
	struct node* node = NULL;
	node = buildlistattailbyref(10);
	printlist(node, "at tail by local ref ");
	insertnth(&node, 10, 100);
	printlist(node, " after inserting at node 10");
}
Пример #20
0
void testmovelastnode()
{
	struct node* node = buildlistattailbyref(10);
	printlist(node, "node");
	movelastnodetofirst(&node);
	printlist(node, "after moving last node to first");

}
Пример #21
0
void testseggregatingevenodd()
{
	struct node* node = buildlistattailbyref(10);
	printlist(node, "node");
	seggregateevenodd(&node);
	printlist(node, "node after seggregating");

}
Пример #22
0
void testbuildlistinsortedorder()
{
	struct node* node = NULL;
	node = buildlistinsortedorder(10);
	printlist(node, "in sorted order ");
	sortedinsert(&node, nn(18));
	printlist(node, " after sorted insert");
}
Пример #23
0
void testdeletenode()
{
	struct node* node = buildlistattailbyref(4);
	printlist(node, "node before deleting");
	printf("\ndelete node = %d\n", node->next->next->next->data);
	delnodeGivenOnlyAPointerToTheNode(node->next->next->next);
	printlist(node, "node after deleting");
}
Пример #24
0
void testSortedInsertbydata()
{
	struct node* node = NULL;
	node = buildlistinsortedorder(10);
	printlist(node, "in sorted order ");
	SortedInsertbydata(&node, 20);
	printlist(node, " after sorted insert");
}
Пример #25
0
void
finish ()
{
  printlist ("predecessors", predecessors);
  printlist ("successors", successors);
  printlist ("fingers", fingers);
  exit (errors > 0);
}
Пример #26
0
void testsortedintersect()
{
	struct node* a = buildlistinsortedorder(10);
	printlist(a, "a");
	struct node* b = buildlistinsortedorder(10);
	printlist(b, "b");
	struct node* result = sortedintersect(a, b);
	printlist(result, "result");
}
Пример #27
0
void testpairwiseswap()
{
	struct node* node = buildlistattailbyref(10);
	printlist(node, "node");
	pairwiseswap(node);
	pairwiseswaprecur(node);
	printlist(node, "after pairwise swap");

}
Пример #28
0
void testdeletenodeifrightgreater()
{
	struct node* node = buildlistattailbyref(10);
	printlist(node, "node");
	//deletenodeifgreatervalueonright(&node);
	deletenodeifgreateronrightwithoutrev(&node);
	printlist(node, "node after deleting");

}
Пример #29
0
void testaddlists()
{
	struct node* a = buildlistattailbyref(10);
	printlist(a, "a");
	struct node* b = buildlistattailbyref(0);
	printlist(b, "b");
	struct node* result = addListbydigits(a, b);
	printlist(result, "result");
}
Пример #30
0
int main()
{
	srand(time(NULL));

	int size;
	printf("NUMBER: ");
	scanf("%d", &size);
	int* num_list = (int*) malloc(size*sizeof(int));
	for (int i = 0; i <  size; i++)
	{
		num_list[i] = rand()%40;
	}
	int* as_sort = (int*) malloc((size+1)*sizeof(int));
	int* de_sort = (int*) malloc((size+1)*sizeof(int));
	for (int i = 0; i < size; i++)
	{
		as_sort[i] = num_list[i];
		de_sort[i] = num_list[i];
	}

	for (int i = 1; i < size; i++)
	{
		int key =  as_sort[i];
		int j = i-1;
		while (key < as_sort[j])
		{
			as_sort[i] = as_sort[j];
			i--;
			j--;
		}
		as_sort[i] = key;
	}
		for (int i = 1; i < size; i++)
	{
		int key =  de_sort[i];
		int j = i-1;
		while (key > de_sort[j] && i > 0)
		{
			de_sort[i] = de_sort[j];
			i--;
			j--;
		}
		de_sort[i] = key;
	}
	printf("NUMLIST: ");
	printlist(num_list, size);
	printf("AS_SORT: ");
	printlist(as_sort, size);
	printf("DE_SORT: ");
	printlist(de_sort, size);
	free(num_list);
	free(de_sort);
	free(as_sort);

	return 0;
}