コード例 #1
0
ファイル: CSLL.c プロジェクト: srinivaskodali/Practice
void insert(int num)
{
	int c = 0;
	struct node *temp;
	temp = head;
	if (temp == NULL) {
		add(num);
	} else {
		do {
			if (temp->data < num)
				c++;
			temp = temp->next;
		printf ("head is %p, temp is %p\n",head,temp);
		}while (temp != head);
		if (c == 0) {
			printf("Adding number\n");
			add(num);
		}
		else if (c < count()) {
			printf("Adding after %d location\n", c);
			addafter(num, ++c);
		} 
		else {
			printf("Appending number\n");
			append(num);
		}
	}
}
コード例 #2
0
ファイル: q5.c プロジェクト: ishon19/LinkedList_01
void insert(int num)
{
    int c=0;
    struct node *temp;
    temp=head;
    if(temp==NULL)
    {
    add(num);
    }
    else
    {
    while(temp!=NULL)
    {
        if(temp->data<num)
        c++;
        temp=temp->next;
    }
    if(c==0)
        add(num);
    else if(c<count())
        addafter(num,++c);
    else
        append(num);
    }
}
コード例 #3
0
ファイル: CIRCLIST.C プロジェクト: b-rajarshi/code_ol_judges
main()
{
	int choice,n,m,po,i;
	last=NULL;
	while(1)
	{
		printf("1.Create List\n");
		printf("2.Add at begining\n");
		printf("3.Add after \n");
		printf("4.Delete\n");
		printf("5.Display\n");
		printf("6.Quit\n");
		printf("Enter your choice : ");
		scanf("%d",&choice);

		switch(choice)
		{
		 case 1:
			printf("How many nodes you want : ");
			scanf("%d",&n);
			for(i=0; i < n;i++)
			{
				printf("Enter the element : ");
				scanf("%d",&m);
				create_list(m);
			}
			break;
		 case 2:
			printf("Enter the element : ");
			scanf("%d",&m);
			addatbeg(m);
			break;
		 case 3:
			printf("Enter the element : ");
			scanf("%d",&m);
			printf("Enter the position after which this element is inserted : ");
			scanf("%d",&po);
			addafter(m,po);
			break;
		 case 4:
			if(last == NULL)
			{
				printf("List underflow\n");
				continue;
			}
			printf("Enter the number for deletion : ");
			scanf("%d",&m);
			del(m);
			break;
		 case 5:
			display();
			break;
		 case 6:
			exit();
		 default:
			printf("Wrong choice\n");
		}/*End of switch*/
	}/*End of while*/
}/*End of main()*/
コード例 #4
0
ファイル: fakdata.cpp プロジェクト: Premislaus/beos-fakBEtur
void pozfaklist::addafter(pozfakdata *data, int offset) {
	pozfakitem *cur = start;
	offset--;
	while ((offset>0) && (cur!=NULL)) {
		offset--;
//		printf("skip [%i], %s\n", offset, cur->data->data[1].String());
		cur = cur->nxt;
	}
	if (cur!=NULL)
			addafter(data, cur);
}
コード例 #5
0
ファイル: 13.c プロジェクト: thenooz/test
int main()
{
	 struct node *p; int f;f=1;
	 p=NULL;
	 append(&p,1);                  //p is the pointer to the first struct node variable
	 append(&p,2);                  //every variable has it's own data and the address to he next unnamed dynamically allocated variable of the struct type
	 append(&p,3);append(&p,4);
	 append(&p,6);append(&p,10);
	 addatbeg(&p,1);
	 addafter(&p,8,6);
	 display(p);
	 add(&p,9);add(&p,11);
	 printf("   p->link->link->num= %d  ",p->link->link->num);
	 dlt(&p,f);
	 printf("\nAftre deletion of node %d :  ",f);
	 display(p);
	 reverse(&p);
	 printf("\nAfter reversal:");
	 display(p);
	 getch();
	 return 0;
	 
}
コード例 #6
0
main()
{
	int choice,data,item;
	struct node *start=NULL;
	while(1)
	{
		printf("1.Create List\n");
		printf("2.Display\n");
		printf("3.Add to empty list\n");
		printf("4.Add at beginning\n");
		printf("5.Add at end\n");
		printf("6.Add after\n");
		printf("7.Add before\n");
		printf("8.Delete\n");
		printf("9.Reverse\n");
		printf("10.Quit\n");
		printf("Enter your choice : ");
		scanf("%d",&choice);
		switch(choice)
		{
		 case 1:
			start=create_list(start);
			break;
		 case 2:
			display(start);
			break;
		 case 3:
			printf("Enter the element to be inserted : ");
			scanf("%d",&data);
			start=addtoempty(start,data);
			break;
		 case 4:
	        printf("Enter the element to be inserted : ");
			scanf("%d",&data);
			start=addatbeg(start,data);
			break;
		 case 5: 
			printf("Enter the element to be inserted : ");
			scanf("%d",&data);
			start=addatend(start,data);
			break;
		 case 6:
			printf("Enter the element to be inserted : ");
			scanf("%d",&data);
			printf("Enter the element after which to insert : ");
			scanf("%d",&item);
			start=addafter(start,data,item);
			break;
		 case 7:
			printf("Enter the element to be inserted : ");
			scanf("%d",&data);
			printf("Enter the element before which to insert : ");
			scanf("%d",&item);
			start=addbefore(start,data,item);
			break;
		 case 8:
			printf("Enter the element to be deleted : ");
			scanf("%d",&data);
			start=del(start,data);
	   		break;
		 case 9:
		 	start=reverse(start);
			break;
		 case 10:
			exit(1);
		 default:
			printf("Wrong choice\n");
	}/*End of switch*/
   }/*End of while*/
}/*End of main()*/
コード例 #7
0
int main()
{
	int choice,n,m,po,i;
	start=NULL;
	while(1)
	{
		printf("1.Create List\n");
		printf("2.Add at begining\n");
		printf("3.Add after\n");
		printf("4.Delete\n");
		printf("5.Display\n");
		printf("6.Count\n");
		printf("7.Reverse\n");
		printf("8.exit\n");
		printf("Enter your choice : ");
		scanf("%d",&choice);
		switch(choice)
		{
		 case 1:
			printf("How many nodes you want : ");
			scanf("%d",&n);
			for(i=0;i<n;i++)
			{
				printf("Enter the element : ");
				scanf("%d",&m);
				create_list(m);
			}
			break;
		 case 2:
			printf("Enter the element : ");
			scanf("%d",&m);
			addatbeg(m);
			break;
		 case 3:
			printf("Enter the element : ");
			scanf("%d",&m);
			printf("Enter the position after which this element is inserted : ");
			scanf("%d",&po);
			addafter(m,po);
			break;
		 case 4:
			printf("Enter the element for deletion : ");
			scanf("%d",&m);
			del(m);
			break;
		 case 5:
			display();
			break;
		 case 6:
			count();
			break;
		 case 7:
			rev();
			break;
		 case 8:
			//exit();
		 default:
			printf("Wrong choice\n");
	}/*End of switch*/
   }/*End of while*/
  getch();
  return 0;
}/*End of main()*/
コード例 #8
0
int main()  
{  
   int i;  
   Head=NULL;  
  
   while(1)   
   {  
      printf(" \nInsert a number \n1. At Beginning");  
      printf(" \n2. At End");  
      printf(" \n3. At a Particular Location in List");  
      printf(" \n\n4. Print the Elements in the List");  
      printf(" \n5. Print number of elements in the List");  
      printf(" \n6. Delete a Node in the List");  
      printf(" \n7. Reverse the linked List");  
      printf(" \n8. Exit");  
      printf(" \n\nChoose Option: ");  
      scanf("%d",&i);   
  
      switch(i)  
      {  
         case 1:  
        {  
            int num;  
            printf(" \nEnter the Number to insert: ");  
            scanf("%d",&num);  
            addbeg(num);  
            break;  
        }  
         case 2:  
         {  
            int num;  
            printf(" \nEnter the Number to insert: ");  
            scanf("%d",&num);  
            append(num);  
            break;  
         }  
  case 3:  
       {  
           int num, loc, k;  
           printf("\nEnter the Number to insert: ");  
           scanf("%d",&num);  
           printf("\nEnter the location Number: ");  
           scanf("%d",&loc);  
            addafter(num,loc);  
           break;  
      }    
  case 4:  
  {  
     printf(" \nElements in the List: ");  
            display();  
            break;  
        }  
  case 5:  
  {  
     display();  
           printf(" \nTotal number of Elements in the List: %d",count());  
     break;  
     }   
  case 6:  
  {  
     int num;  
           printf(" \nEnter the number to be deleted from List: ");  
           scanf("%d",&num);  
           delnode(num);  
          break;  
      }  
  case 7:  
  {  
     reverse();  
            display();  
            break;  
      }  
    case 8:  
   {  
     struct node *temp;  
      
       while( Head!=NULL)  
     {  
        temp = Head->next;  
        free(Head);  
        Head=temp;  
     }  
       exit(0);  
   }  
  default:   
  {  
     printf("\nWrong Option choosen");  
         }  
      }/* end if switch */  
   }/* end of while */  
}/* end of main */