# help me to find answer!

Page 1 of 1

## 1 Replies - 674 Views - Last Post: 29 May 2008 - 07:56 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=53298&amp;s=56994d505122e0f6edf8b76fdee56119&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sid2008

Reputation: 0
• Posts: 12
• Joined: 01-April 08

# help me to find answer!

Posted 29 May 2008 - 06:52 AM

Hi everyone...I am posting again the question which was asked in my exam actually i got correction in it but i dont know the correct answer if someone have question plz help me bec just for my curiocity bec exam was over and i got too less grade so i just want to know the answer now..

Consider the following C++ declarations for problems 1 through 10. Complete any 7 of the 10 problems. Extra credit will be given to additional correct problems.

typedef int elementType;

class node1{
friend class list1;
private:
elementType data;
node1 * next;
};

class node2{
friend class list2;
private:
elementType data;
node2 * next;
node2 * prev;
};

class list1 {
public:
list1() {first =NULL;}//constructor
. . . //other member functions

private:
node1 * first;
};

class list2 {
public:
list2() {first =NULL;}//constructor
. . . //other member functions

private:
node2 * first;

};

here are the questions

2. Write function to sum the data that in stored in a singly linked list. This function should return an integer representing the sum of the data in the list.

int list1::Sum()

4. Write a member function to find the last node in a doubly circular linked list. This function returns a pointer pointing to the last node in the linked list.

node2 * list2::findlast()

you dont know but giving me the reply of those questions you would help me a lot...

Is This A Good Question/Topic? 0

## Replies To: help me to find answer!

### #2 realNoName

• D.I.C Regular

Reputation: 7
• Posts: 343
• Joined: 04-December 06

## Re: help me to find answer!

Posted 29 May 2008 - 07:56 AM

i dont have a compiler in front of me so the syntax might be a little off but it should be more then enough to get you the answers

2) all you have to do for this is step through the link list
```int list1::Sum()
{
//Temp pointer so we can walk through the list
node1 * walker = first;

int sum = 0;

//keep going until walker is false
//  same thing as
//	while(walker != NULL)
//	while(walker == true)
while(walker)
{
sum += walker->data;
walker = walker->next;
}

return sum;
}
```

4) if this is a true circular link list then

```node2 * list2::findlast()
{
//because its circular all we should have to do is
//look at the first node and return the prev pointer
return first->prev;
}
```

This post has been edited by realNoName: 29 May 2008 - 08:02 AM

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }