Hello, I have made an attempt at writing this code but it doesn't seem to do much, am kind of new to the concept of lisp lists therefore i believe i don't quiet understand what i should be doing, anyways here is what i have tried:
import java.util.*; public class removNum{ public static void main(String[] args){ Scanner in = new Scanner(System.in); LispList<Integer> list; System.out.println("Enter a list (of integers): "); String str = in.nextLine(); list = removePos(list); System.out.println(list); } public static LispList removePos(LispList list, int n){ if(0==n){ return list.getTail(); } else{ return new LispList(list.getHead(),removePos(list.getTail(),n-1)); } } }
Well basically what i'm trying to do is to write a recursive method which takes a list and an integer x, and deletes the integer at position x in the list, e.g. if the list is [2,5,6,40,8,9,45] and the integer is 40, the method should return [2,5,6,40], so nothing after the integer should be printed.
I don't expect anyone to write up the solution for me but a nudge in the right direction would be greatly appreciated.