i need help with my function

How do I Write a function that takes two linked list
as input arguments these linked list contain numbers like
this:

num1->3->5->2->NULL (assuming that number 1 is 352)
num2->4->3->9->1->NULL (assuming that number 2 is 4391)

The function should return 1 if num1 points
to a linked list which represents a smaller number than
the number pointed to by num2 linked list. Otherwise,
it returns -1. If both linked list point to exactly the
same number, returns a 0.
are we talking about the std::list?
yes
Use below function. It is written by using std:list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int fun(list<int> &num1,list<int> &num2)
{
	if(num1.size()<num2.size())
		return 1;
	else if(num1.size()>num2.size())
		return -1;
	else
	{
		for(int i=0;i<num1.size();i++)
		{
			if(num1[i]<num2[i])
				return 1;
			else if(num1[i]>num2[i])
				return -1;
		}

		return 0;
	}
}
Last edited on
Topic archived. No new replies allowed.