Welcome to W3Courses
 Like Us on Facebook

Delete All

Delete All Delete First Delete Last Source Code for Linked List Functions and Procedures in C programming

Following is the Source Code to Create Linked List Functions and Procedures (Delete All, Delete First, Delete Last)

(1)
list del_all (list L, data alpha)
{
 if (null(L))
  return nullist();
 else if (car(L) = = alpha)
  return del_all(cdr(L), alpha);
 else
  return cons(car(L), del_all(cdr(L), alpha));
}

Share

Delete all occurrences of an Element from a List using Prolog Source Code

The following code deletes all occurrences of an element from a list

CODE
deleteall([],A,[]).
deleteall([H|T],A,Result) :- H=A, deleteall(T,A,Result).
deleteall([H|T],A,[H|Result]) :- deleteall(T,A,Result).


RESULT
?- deleteall([a,b,a,c],a,Result).
Result = [b, c]
Yes


 

Share

Delete all Occurrences of an Element from a List Using Scheme Source Code

The following code deletes all occurrences of an element from a list

CODE
 (define deleteall( lambda (x y)
      (if (null? y )
            ()
      (if (eqv? (car y) x)
           (deleteall x (cdr y))
      (cons (car y) (deleteall x (cdr y)))))))

Share