Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

linked list (delete function)

Avatar of rmtogether
rmtogether asked on
C
7 Comments1 Solution719 ViewsLast Modified:
Hi,

I have linked variable list program, it can do insert() and print(). I would like to add delete() could someone help me about this?

---------------------
# include <stdio.h>
# include <string.h>   //for strcmp function
# define MAXIMUM 10
# define MAX 8
# define NO 0
# define YES  1

void insertll(void);  
void printll(void);  

char name[MAXIMUM][MAX];
int link[MAXIMUM];
int prev, next;
int Start, Avail;

main(){
       char response[MAX];
       Start=0;
       Avail=1;
       strcpy(name[0],"AAAAAA");
       link[0]=-1;
       printf("Plese enter i/p/q:\n");
       scanf("%s",response);
       
       while(response[0]!='q'&&response[0]!='Q'){
             switch(response[0]){
             case 'I':
             case 'i':
                  insertll();
                  break;
             case 'P':
             case 'p':
                  printll();
                  break;
             default:
                  printf("Error input, Please enter i/p/q:\n");
                  break;
             }//end of switch
             
       printf("Please enter i/p/q:\n");
       scanf("%s",response);
       }//end while
       printf("Program END\n");
       system("pause");
}


void insertll(void)           /*function for insert to linked list*/
{
  char response[MAX];  
  int ReadyIns;
  if(Avail==MAXIMUM)
     printf("overflow!\n");
  else
  {
     printf("enter a name:");
     scanf("%s",response);
     next=Start;          
     ReadyIns=NO;
        while((next!=1)&&!(ReadyIns)){         /* -1: last one */
           if(strcmp(response,name[next])==0)
            {
              prev=next;
              next=link[next];
             }//end of if
           else
             ReadyIns=YES;
        }//end while
         
          strcpy(name[Avail],response);
          link[Avail]=link[prev];
          link[prev]=Avail;
          Avail=Avail+1;            /*next available space*/
  }/*end of else*/
     
}/*end of insertll*/
               
 
void printll(void)       /*function for display linked list*/
{
     char response[MAX];
     int j;
     /*print logically or physically*/
     printf("Please enter l or p (Logical or Physical)\n");    
     scanf("%s",response);
     
     if(response[0]=='l'||response[0]=='L')  /*logically print linked list*/
     {
       next=Start;
         while(next!=-1)   /* -1: last one */
         {        
           printf("%d %s %d\n",next, name[next],link[next]);
           printf("\n");
           next=link[next];
         }//end while
     }//end if
     
     if(response[0]=='p'||response[0]=='P')  /*physically print link list*/
        for(j=0;j<MAXIMUM;j++)
        {
           printf("%d %s %d\n",j,name[j],link[j]);
           printf("\n");
        }//end for            
               
}
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent OlsenFlag of United States of America imageData Warehouse / Database Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answers