Example #1
0
static void
do_finduids(nsc_bucket_t *ptr, int *table, int uid)
{

	/*
	 * be careful with ptr - it may be -1 or NULL.
	 */
	if (ptr != NULL && ptr != (nsc_bucket_t *)-1) {
		insertn(table, ptr->nsc_hits, uid);
	}
}
Example #2
0
static void
do_findnams(nsc_bucket_t *ptr, int *table, char *name)
{

	/*
	 * be careful with ptr - it may be -1 or NULL.
	 */
	if (ptr != NULL && ptr != (nsc_bucket_t *)-1) {
		char *tmp = (char *)insertn(table, ptr->nsc_hits,
			(int)strdup(name));
		if (tmp != (char *)-1)
			free(tmp);
	}
}
Example #3
0
void main()
{ start=NULL;
    int value,k=0,choice,pos;
    char ans,ch;
    printf("MENU DRIVEN PROGRAM:\n");
    printf("1.Create linked list\n");
    printf("2.Insert the value at the end\n");
    printf("3.Insert the value at the begining\n");
    printf("4.Insert the value at nth position\n");
    do
    {
     printf("What do you want to do:");
     scanf("%d",&choice);
     switch(choice)
     {
         case 1:if(k==1)
                printf("\nYou have already created linked list!!!!! ");
                else
                {
                do
                {
                    printf("\nEnter the value:");
                    scanf("%d",&value);
                    create(value);
                    fflush(stdin);
                    printf("Do you want to add more element in the list?");
                    scanf("%c",&ch);
                }while(ch=='y'||ch=='Y');
                 k++;
                }break;
         case 2:if(k==1)
                {printf("\nEnter the value to insert at the end:");
                 scanf("%d",&value);
                 insertend(value);
                }
                else printf("\nFirstly create a linked list!!!!");
                break;
         case 3:if(k==1)
                {printf("\nEnter the value to insert at the begining:");
                 scanf("%d",&value);
                 insertbeg(value);
                }
                else printf("\nFirstly create a linked list!!!!");
                break;
         case 4:if(k==1)
                {printf("\nEnter the value and position:");
                 scanf("%d%d",&value,&pos);
                 insertn(value,pos);
                }
                else printf("\nFirstly create a linked list!!!!");
                break;
     }
     fflush(stdin);
      printf("\nDo you want to perform another operation?");
      scanf("%c",&ans);
    }while(ans=='y'||ans=='Y');
    printf("\nThe linked list is:");
    temp=start;
    printf("%d\t",temp->data);
    while(temp->next!=NULL)
    {
        temp=temp->next;
        printf("%d\t",temp->data);

    }
}
void main()
{
 NODE *s1,*s2;
 int ch;
 s1=NULL;
 s2=NULL;
 while(1)
 {
  clrscr();
  printf("Enter choice:\n");
  printf(" 1.Append element at end\n 2.Concatinate two lists\n");
  printf(" 3.Free all nodes in a list\n 4.Reverse a list\n");
  printf(" 5.Delete last element\n 6.Delete nth element\n");
  printf(" 7.Combine two ordered list into single ordered list\n");
  printf(" 8.Find union of two lists\n 9.Find intersection of two lists\n");
  printf("10.Insert after nth element\n11.Delete every second element\n");
  printf("12.Place elements in order\n13.Return sum of data\n");
  printf("14.Return number of elements\n15.Make second copy of list\n");
  printf("16.Move node forward to n positions\n17.Exit\n");
  scanf("%d",&ch);
  clrscr();
  if(ch>0&&ch<=16)
   s1=create(s1);
   disp(s1);
  switch(ch)
  {
   case 1:s1=append(s1);break;
   case 2:s2=create(s2);disp(s2);s1=concat(s1,s2);break;

   case 3:s1=fr(s1);
   printf("List freed\n");
   disp(s1);
   break;
   
   case 4:s1=rev(s1);break;
   case 5:s1=dellast(s1);break;
   case 6:s1=deln(s1);break;
   case 7:s2=create(s2);disp(s2);s1=comb(s1,s2);break;
   case 8:s2=create(s2);disp(s2);s1=uni(s1,s2);break;
   case 9:s2=create(s2);disp(s2);s1=inter(s1,s2);break;
   case 10:s1=insertn(s1);break;
   case 11:s1=del2(s1);break;
   case 12:s1=sort(s1);break;
   case 13:printf("Sum of elements=%d",sum(s1));break;
   case 14:printf("Number of elements=%d",elements(s1));break;
   
   case 15:
   s2=copy(s1);
   printf("Second list:\n");
   disp(s2);
   break;
   
   case 16:s1=forward(s1);break;
   case 17:exit(0);break;
   default:printf("Wrong choice.Enter again");break;
  }
  if(ch!=3&&ch!=13&&ch!=14&&ch!=15&&ch>0&&ch<=16)
  {
   printf("\nResult:");
   disp(s1);
  }
   s1=fr(s1);
   s2=fr(s2);
   getch();
 }   
}