Question

Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list...

Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list identical to the parameter except the last element has been deleted. For example, (DEL-LELEMENT '(8 2 3 7 6)) should return (8 2 3 7) *Please explain your code and submit the source code. Please test the function with the provided example and submit a screen shot of the testing result.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As you have not given any particular language, I am executing this problem in Java using ArrayList. Refer to the comments for explanation.

PROGRAM


import java.util.List;
import java.util.ArrayList;
  
public class Main
{
//function that deletes last element of list
public static ArrayList<Integer> delElement(ArrayList<Integer> list) {
list.remove(list.size()-1); //remove last element by getting the last index of list
return list; //returning list
}
public static void main(String[] args)
{
ArrayList<Integer> list = new ArrayList<>(); //new ArrayList
//adding elements in Arraylist
list.add(16);
list.add(24);
list.add(12);
list.add(68);
list.add(7);

System.out.println("ArrayList : " + list); //printing the original ArrayList
  
//printing the list after deleting the last element
System.out.println("\nModified ArrayList : " + delElement(list));
}
}

Add a comment
Know the answer?
Add Answer to:
Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT