Thread: Delete In Double Linked List

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    6

    Delete In Double Linked List

    Please Help Me to Make DELETE Function DELETE it from Linked List


    Detail Requirement:

    1. The iPhotoShoppe Application must be created using Menu.




    1. Open Picture
    2. Checking Metadata
    3. Delete
    4. Exit





    1. In menu Open Picture there are conditions:
      1. Prompt user to input picture name for example

    filename.extension example (hello.jpg).

    1. Validate extension, only ‘jpg / png / gif’.
    2. Random 7 editing process (‘paste’,’delete’,’copy’,’crop’,’layer’).

    Insert to Linked-list.


    1. In menu Checking Metadata there are conditions:
      1. There is error saying No Picture Yet if no data entered yet.
      2. Loop all editing from all the picture. Set tag as hoax if contain min 2 layer and 2 crop.



    1. In menu Delete there are conditions:
      1. Delete all picture tagged with hoax start from the last picture entered.
      2. Remove all picture that contain ‘delete’ in editing process more than 3 times.
      3. Print all picture (not yet deleted), and All picture deleted separately.

    Delete In Double Linked List-halamanutama-png

    Delete In Double Linked List-menu3-jpg

    My Code :

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    
    
    struct data{
    	char nama[100];
    	char format[2];
    	char extension[4];
    	char proses1[10];
    	char proses2[10];
    	char proses3[10];
    	char proses4[10];
    	char proses5[10];
    	char proses6[10];
    	char proses7[10];
    	char tanda[10000];
    	data *next,*prev;
    }*head,*tail,*current;
    
    
    void pushTail(char nama[],char format[],char extension[],char proses1[],char proses2[],char proses3[],char proses4[],char proses5[],char proses6[],char proses7[],char tanda[])
    {
    	current = (data*)malloc(sizeof(struct data));
    	
    	strcpy(current->nama,nama);
    	strcpy(current->format,format);
    	strcpy(current->extension,extension);
    	strcpy(current->proses1,proses1);
    	strcpy(current->proses2,proses2);
    	strcpy(current->proses3,proses3);
    	strcpy(current->proses4,proses4);
    	strcpy(current->proses5,proses5);
    	strcpy(current->proses6,proses6);
    	strcpy(current->proses7,proses7);
    	strcpy(current->tanda,tanda);
    	current->next=current->prev=NULL;
    	
    	if(head==NULL)
    	{
    		head=tail=current;
    	}
    	else
    	{  
            current->prev=tail;
    		  tail->next=current;
    		  tail=current;
    	}
    }
    
    
    
    
    void checkMetadata()
    {
        current = (data*)malloc(sizeof(struct data));
        int countLayer = 0;
        int countCrop = 0;
        data *temp = head;
        int temp1[10000];
        int indeks = 0;
        char cleanOrHoax[10000];
        while(temp!=NULL)
        {
            if(strcmp(temp->proses1,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses2,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses3,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses4,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses5,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses6,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses7,"layer")==0)
            {
                countLayer++;
            }
            if(strcmp(temp->proses1,"crop")==0)
            {
                countCrop++;
            }
            if(strcmp(temp->proses2,"crop")==0)
            {
                countCrop++;
            }
            if(strcmp(temp->proses3,"crop")==0)
            {
                countCrop++;
            }
            if(strcmp(temp->proses4,"crop")==0)
            {
                countCrop++;
            }
            if(strcmp(temp->proses5,"crop")==0)
            {
                countCrop++;
            }
            if(strcmp(temp->proses6,"crop")==0)
            {
                countCrop++;
            }
            if(strcmp(temp->proses7,"crop")==0)
            {
                countCrop++;
            }
            if(countLayer >=2 && countCrop>=2)
            {
                printf("%s%s%s => hoax => didn't pass to our sosmed\n",temp->nama,temp->format,temp->extension);
                strcpy(current->tanda,"hoax");
            }
            else
            {
                printf("%s%s%s => clean => pass to our sosmed\n",temp->nama,temp->format,temp->extension);
                strcpy(current->tanda,"clean");
            }
            temp = temp->next;
            countLayer = 0;countCrop = 0;
        }
        printf("\n\n");
        printf("Press any key to continue..");
        getchar();
    }
    
    
    void deleteData()
    {
        
    }
            
    
    
    void view()
    {
    	current=head;
    		while(current!=NULL)
    		{
    		    printf("\n");
    			printf("%s%s%s\n",current->nama,current->format,current->extension);
    			printf("| %s >| %s >| %s >| %s >| %s >| %s >| %s >",current->proses1,current->proses2,current->proses3,current->proses4,current->proses5,current->proses6,current->proses7);
    			current=current->next;
    		}
    	printf("\n\n");
    }
    
    
    int main()
    {
        int pilihan;
        char nama[100],format[2],extension[4];
        int proses;
        char proses1[10];
        char proses2[10];
    	char proses3[10];
    	char proses4[10];
    	char proses5[10];
    	char proses6[10];
    	char proses7[10];
        int tampung[10];
        do{
            
             for(int i=0;i<30;i++)
            {
                printf("\n");
            }
            view();
            printf("Smart Metadata\n");
            printf("\\NULL\\\n\n");
            printf("iPhotoShoppe\n");
            printf("1. Open Picture\n");
            printf("2. Checking Metadata\n");
            printf("3. Delete\n");
            printf("4. Exit\n");
            printf("Select Menu [1..4]: ");
            scanf("%d",&pilihan);fflush(stdin);
            
            switch(pilihan)
            {
                case 1:
                    do{
                        printf("\n");
                         printf("Input Filename [name.extension]: ");
                         scanf("%[^.]%c%s",nama,format,extension);
                         
                         if(strcmp(extension,"jpg")!=0 && strcmp(extension,"png")!=0 && strcmp(extension,"gif")!=0)
                         {
                             printf("Invalid Extension <'jpg/png/gif'> only!\n\n");
                         }
                    }while(strcmp(format,".")!=0 || (strcmp(extension,"jpg")!=0 && strcmp(extension,"png")!=0 && strcmp(extension,"gif")!=0));
                    srand(time(0)); 
                    for (int c = 0; c < 7; c++) {
                        proses = rand() % 5;
                        tampung[c] = proses;
                    }
                    for(int d=0;d<7;d++)
                    {
                        if((tampung[d]==0))
                        {
                            if(d==0)
                            {
                                strcpy(proses1,"paste");
                            }
                            if(d==1)
                            {
                                strcpy(proses2,"paste");
                            }
                            if(d==2)
                            {
                                strcpy(proses3,"paste");
                            }
                            if(d==3)
                            {
                                strcpy(proses4,"paste");
                            }
                            if(d==4)
                            {
                                strcpy(proses5,"paste");
                            }
                            if(d==5)
                            {
                                strcpy(proses6,"paste");
                            }
                            if(d==6)
                            {
                                strcpy(proses7,"paste");
                            } 
                        }
                        else if(tampung[d]==1)
                        {
                            if(d==0)
                            {
                                strcpy(proses1,"delete");
                            }
                            if(d==1)
                            {
                                strcpy(proses2,"delete");
                            }
                            if(d==2)
                            {
                                strcpy(proses3,"delete");
                            }
                            if(d==3)
                            {
                                strcpy(proses4,"delete");
                            }
                            if(d==4)
                            {
                                strcpy(proses5,"delete");
                            }
                            if(d==5)
                            {
                                strcpy(proses6,"delete");
                            }
                            if(d==6)
                            {
                                strcpy(proses7,"delete");
                            } 
                        }
                        else if(tampung[d]==2)
                        {
                            if(d==0)
                            {
                                strcpy(proses1,"copy");
                            }
                            if(d==1)
                            {
                                strcpy(proses2,"copy");
                            }
                            if(d==2)
                            {
                                strcpy(proses3,"copy");
                            }
                            if(d==3)
                            {
                                strcpy(proses4,"copy");
                            }
                            if(d==4)
                            {
                                strcpy(proses5,"copy");
                            }
                            if(d==5)
                            {
                                strcpy(proses6,"copy");
                            }
                            if(d==6)
                            {
                                strcpy(proses7,"copy");
                            } 
                        }
                        else if(tampung[d]==3)
                        {
                            if(d==0)
                            {
                                strcpy(proses1,"crop");
                            }
                            if(d==1)
                            {
                                strcpy(proses2,"crop");
                            }
                            if(d==2)
                            {
                                strcpy(proses3,"crop");
                            }
                            if(d==3)
                            {
                                strcpy(proses4,"crop");
                            }
                            if(d==4)
                            {
                                strcpy(proses5,"crop");
                            }
                            if(d==5)
                            {
                                strcpy(proses6,"crop");
                            }
                            if(d==6)
                            {
                                strcpy(proses7,"crop");
                            } 
                        }
                        else if(tampung[d]==4)
                        {
                            if(d==0)
                            {
                                strcpy(proses1,"layer");
                            }
                            if(d==1)
                            {
                                strcpy(proses2,"layer");
                            }
                            if(d==2)
                            {
                                strcpy(proses3,"layer");
                            }
                            if(d==3)
                            {
                                strcpy(proses4,"layer");
                            }
                            if(d==4)
                            {
                                strcpy(proses5,"layer");
                            }
                            if(d==5)
                            {
                                strcpy(proses6,"layer");
                            }
                            if(d==6)
                            {
                                strcpy(proses7,"layer");
                            } 
                        }
                    }
                   pushTail(nama,format,extension,proses1,proses2,proses3,proses4,proses5,proses6,proses7,"clean");
                break;
                case 2:
                    current = head;
    			    if(current==NULL)
    			    {
    			         printf("\nNo Picture Yet\n");  
                        getchar();
                    }
                    else
                    {
                        printf("\n");
                        checkMetadata();
                    }
                break;
                case 3:
                        deleteData();
                break;
            }
        }while(pilihan < 1 || pilihan > 4 || pilihan !=4);   
    	return 0;
    }
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    You need to get rid of the global variables! That's just bad programming. Make a List struct, init it in main and pass it around.

    I think maybe the structure of your list is wrong. You have a list of files where each node contains an array of operations. I wonder if you were supposed to have a list of operations instead of an array.
    Code:
    a.png -> b.png -> c.png -> 0
      |        |        |
     copy    layer    paste
      |        |        |
     crop      0      delete
      |                 |
      0                 0
    You could get rid of a lot of code duplication by using arrays instead of numbered variable names.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    6
    Thank You Very Much, From Your Explanation and Figure, Finally I Found My Mistake. Very Awesome

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic List Char Array & Double Linked List
    By Roadrunner2015 in forum C Programming
    Replies: 18
    Last Post: 10-20-2013, 01:31 PM
  2. Delete and destroy in double linked lists
    By Delia in forum C Programming
    Replies: 19
    Last Post: 05-26-2010, 10:09 PM
  3. double linked list
    By TNA$H in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 07:45 AM
  4. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  5. help for linked list(double)
    By Ausandy in forum C Programming
    Replies: 4
    Last Post: 08-19-2002, 03:58 AM

Tags for this Thread