## Ordering a list depending on the order of elements in anothe

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

### Ordering a list depending on the order of elements in anothe

I have a list

Code: Select all
`(SetQ L '(1 j 3 k 4 h 5 n 6 w))`

I have to do a function Order that has a list with 'n' atoms at entry, it must check if each atom of that list is contained in list L and order them according to the order specified in list L, if the atom is not part of the list L then the result will be displayed

Code: Select all
`(Defun Order lst)(SetQ L2'(w o 5 j 3))`

I want to verify this:

Code: Select all
`(Order L2)`

result should return:
Code: Select all
`(J 3 5 W)`
halastoi

Posts: 3
Joined: Wed Apr 25, 2012 12:36 am

### Re: Ordering a list depending on the order of elements in an

Sorry, but this forum is not called "we make your homework".
edgar-rft

Posts: 224
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

### Re: Ordering a list depending on the order of elements in an

I moved the topic to the homework forum. The source language is CL.

nuntius

Posts: 532
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

### Re: Ordering a list depending on the order of elements in an

So this problem is designed to step through one list and at each atom check if it exists in the other.

This problem is asking you to make two recursive tasks, one based on L and one on L2. I suggest you start with L as it defines your order.

L's function:
If null, return nil
else If L2 contains car L return car L
else call L's function with cdr L.

L2's funciton:
If L2 null, return nil
else if car L equals car L2 return car L2
else call L2's function with cdr L2

Put those two together and there you go.
jecxjo

Posts: 3
Joined: Thu Mar 01, 2012 11:29 am