Exemple #1
0
/* Story 3: find_sll */
void test3(void)
{
  list test_list = NULL;

  printf("Testing story 3: find_sll\n");
  test_list = init_sll(test_list);
  print_list("Searching in", test_list);
  print_list("Searching for 0", find_sll(test_list, 0));
  print_list("Searching for 1", find_sll(test_list, 1));
  print_list("Searching for 3", find_sll(test_list, 3));
  print_list("Searching for 4", find_sll(test_list, 5));
}
Exemple #2
0
int menu_body(char ch,int choice)
{

	static int flag;
	int data,result;
	switch (ch)
	{
	case ESC:
	{
		clrscr();
		flag=1;
	}
	break;

	case ENTER:
	{
		switch(choice)
		{
		case 0:
		{
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			puts("Enter the new element to list");
			fflush(stdout);
			scanf("%d",&data);
			result=insert_node_sll(&start,data);
			(result==1)?puts("Element has been added"):puts("Faild to enter the element");
			puts("Enter any key to back to menu");
			getch();
		}
		break;
		case 1:
		{
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			print_sll (start);
			puts("Enter any key to back to menu");
			getch();
		}
		break;
		case 2:
		{
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			puts("Enter an element to find it");
			fflush(stdout);
			scanf("%d",&data);
			result=find_sll (start ,data);
			(result==1)?printf("Element %d has been found\n",data)
					   :printf("Element %d is not presented in list\n",data);
			puts("Enter any key to back to menu");
			getch();
			break;
		}
		break;

		case 3:
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			puts("Enter an element to delete");
			fflush(stdout);
			scanf("%d",&data);
			result=delete_sll(&start,data);
			(result==1)?puts("Element has been deleted"):puts("Element has not been found");
			puts("Enter any key to back to menu");
			getch();
			break;

		case 4:
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			result=get_count_sll(start);
			printf("Number of elements in list is %d\n",result);
			puts("Enter any key to back to menu");
			getch();
			break;

		case 5:
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			free_list(&start);
			getch();
			break;

		case 6:
			clrscr();
			gotoxy(0,0);
			/*Please Add your function here*/
			reverse_sll(&start);
			print_sll (start);
			getch();
			break;

		case 7:
			flag=1;
			break;

		}
	}
	}

	return(flag);

}