// int size = 0;
int main()
{
	//Initialize Crcular linked list with NULL head
	node *head = NULL;
	int data = 10;
	// printf("Enter: ");
	// scanf("%d",&data);
	insertLast(&head, data);
	insertFirst(&head, 5);
	print(&head);
	printf("Size: %d\n", size(&head));

	printf("Insert at position 1\n");
	insertAtPosition(&head, 1,1);
	print(&head);
	printf("Size: %d\n", size(&head));

	printf("Insert at position 4\n");
	insertAtPosition(&head, 15,4);
	print(&head);
	printf("Size: %d\n", size(&head));

	deleteFirst(&head);
	print(&head);
	printf("Size: %d\n", size(&head));	

	deleteLast(&head);
	print(&head);
	printf("Size: %d\n", size(&head));	

	deleteAtPosition(&head,2);
	print(&head);
	printf("Size: %d\n", size(&head));	

	deleteAtPosition(&head,1);
	print(&head);
	printf("Size: %d\n", size(&head));	

	printf("New Circular linked list\n");
	node *head1 = NULL;
	createList(&head1);
	print(&head1);

	printf("Enter data want to search: ");
	scanf("%d", &data);
	search(&head1,data);

	printf("Sort a circular linked list\n");
	sort(&head1);
	print(&head1);

}
コード例 #2
0
struct node* noHalfEvenOddValues(struct node *root)
{
	if(root!= NULL)
	{
		int i=1,j=0,n=sizeOf(root);
		struct node *temp = (struct node*)malloc(sizeof(struct node));
		temp = root;
		while(temp!=NULL)
		{
			if(j<n/2)
			{
				if(temp->item%2 == 1 || temp->item%2 == -1)
				{
					temp = temp->next;
					root = deleteAtPosition(i,root);
				}
				else
				{
					i++;
					temp = temp->next;
				}
			}
			else
			{
				if(temp->item%2 == 0)
				{
					temp = temp->next;
					root = deleteAtPosition(i,root);
				}
				else
				{
					i++;
					temp = temp->next;
				}
			}
			j++;
		}
	}
	return root;
}
コード例 #3
0
int main(){

	node* head = NULL;
	push(&head,1);
	push(&head,2);
	printList(head);
	deleteNode(&head,1);
	push(&head,3);
	push(&head,4);
	printList(head);
	deleteAtPosition(&head,1);
	printList(head);

	return 0;
}
コード例 #4
0
main()	
	{
	int n;
    printf("Chose from the options:\n");
    while(1)
           {
           printf("\n1.Add elements to the Linked List \n");
           printf("2.Delete Node At Beginning \n");
           printf("3.Delete Node At End \n");
           printf("4.Delete Node At Any position \n");
           printf("5.Display \n");
           printf("6.exit \n");
           scanf("%d",&n);
           switch(n)
                {
                case 1:{               		   
                	   add_Element(getvalue());
                	   break;
                	   }
                case 2:{               		   
                	   deleteFirstNode();
                	   break;
                	   }
                case 3:{               		   
                	   deleteLastNode();
                	   break;
                	   }   
                case 4:{              
                       int pos;	   
                       printf("Enter the position to delete:\n");          
                       scanf("%d",&pos);          
                	   deleteAtPosition(pos);
                	   break;
                	   }           	   
                case 5:{
                	   display_Traversing();
                	   break;
                	   }
                case 6:
                       exit(1);	   
                default:
                		printf("Wrong Input!!!\n");
                }
           printf("\n\n");     	
           }     	
	}    
コード例 #5
0
ファイル: homework3.c プロジェクト: qhauict13/hustCbasic
int main(int argc, char *argv[])
{
  FILE *ft,*fd;

  while (1) {
    switch(getmenu("Import DB from NokiaDB.dat;Print data;Insert data;Delete data;Search Data & modify data;Devide list & Extract List;Reverse list;Save to file;Quit",9,0))
      {  mfflush();
      case 1:
        if((fd = fopen(DAT,"r+b")) == NULL) printf("\t\tCan't read file %s",DAT);
        else {
          if(getmenu("Insert Whole;Insert Part",2,0) == 1) {
              importfdat(fd,1,1);
          } else {
            if(getmenu("From Begin;From ending",2,0) == 1) importfdat(fd,2,1);
            else importfdat(fd,2,2);
          }
            printf("\t\tImport DB complete !!\n");
            fclose(fd);
        } break;
      case 2:if(root == NULL && root2 == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          if(root2 == NULL) printdat(root);
          else {
            int c ;
            if((c = getmenu("Print data of first list;Print data of second list",2,0)) == 1)
              printdat(root); else printdat(root2);
          }
        }
        break;
      case 3:if(root == NULL){
          indent(2); printf("Import data first !!\n");
        } else {
          int c;
          VARTYPE p;
          printf("\t\tModel of phone :");scanf("%[^\n]",p.model);mfflush();
          printf("\t\tSize of phone :");scanf("%d",&p.size);mfflush();
          printf("\t\tPhone's size of screen :");scanf("%f",&p.screen);mfflush();
          printf("\t\tPhone's price :");scanf("%d",&p.price);mfflush();
          if((c = getmenu("Insert at Begining;Insert at Ending;Insert at Position",3,0)) == 1) {
            insertB(p);
          } else if (c == 2) insertE(p);
          else {
            int z;
            node *g;
            do {
            printf("\t\t Where you want to insert (if you don't want to insert anymore input -1 !! 1st = 0 postion) :");scanf("%d",&z);mfflush();
            g = insertAtPosition(p,z);
            } while (g == NULL && z != -1);
          }
        }break;
      case 4:if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          int c;
          if((c = getmenu("Delete at Postion;Delete current;Delete first",3,0))==1)  {
            int p;
            printf("\t\t Where you want to delelte (if you don't want to insert anymore input -1 !! 1st = 0 postion) :");scanf("%d",&p);mfflush();
            deleteAtPosition(p);
          } else if(c == 2) delNode(cur);
          else if(c == 3) delNode(root);
        } break;
      case 5:
        if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          int cc;
          if((cc = getmenu("Search data;Modify data",2,0)) == 1){
            int c;
            if((c = getmenu("Search By name;Search By Price",2,0)) ==1)
              search(root,1);
            else search(root,2);
          } else {
            modify();
          }
        } break;
      case 6:
        if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          int c;
          if((c = getmenu("Devide List;Extract list",2,0))==1){
            int p;
            printf("\t\tPostion you want to devide list : ");scanf("%d",&p);mfflush();
            root2 = devideList(root,last,p);
          } else {
            int p,n;
            printf("\t\tPostion you want to start extract list : ");scanf("%d",&p);mfflush();
            printf("\t\tLength of extract list : ");scanf("%d",&n);mfflush();
            extractList(p,n);
          }
        }break;
        case 7:if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          reversel();
        }break;
      case 8:if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          if((fd = fopen(DAT,"w+b")) == NULL) printf("Can't create file %s",DAT);
          else {
            exporttdat(fd);
          }
        }break;
      case 9:
        freelist(root);
        freelist(root2);
        indent(2);printf("Exit Program !!\n");
        return 0;
      }
  }
}