please help me write a function which will return the last element in an unsorted list.
the prototype of the function should be
ItemType ReturnLastItem();
we should assume that the list is not empty ans it shouldnt change after the program is executed..
pleeeeeeeeease help me

Show some effort first and then people will help you. Don't expect others to do your work.

Just an idea: The class could contain a static pointer that would point to the last element. You could set it in the constructor.

i really have no idea how it is supposed to be soled..
there is no constructor in the unsorted list right? only in the stack and queue

here is a try..plz help

Void returnLastItem(ItemType& item)
{
int location=0;
if(//the pointer in the last item is NULL then execute(i dont know how to write this))

item = info[location];//i think this is to print
}

>please help me write a function which will return the last element in an unsorted list.
How appropriately vague. When you say "last element", what do you mean? Do you mean the physical last item or the last sorted item? When you say "list", do you mean an array or a linked list? It could be as simple as saying list[N - 1] .

You haven't given us nearly enough background information to answer your question adequately.

i should add a member function ReturnLastItem () to the UnsortedType ADT that returns the last element in the list. The function has the following prototype:
ItemType ReturnLastItem();
Preconditions: List is initialized and not empty.
Postconditions: List is unchanged.
could u help me now?

>could u help me now?
I'd say no, since you answered neither of my questions.

mmmm i mean the last itwem in the list..it shouldnt be sorted
ex: the lists contains the following
4
5
12
4
the output of the program shpuld be 4
ans when i say list i mean a linked list..
can u help now plz?

Show us the definition of the "list".

what definition?
there is no diffenetion..all i was given was the following:
add a member function ReturnLastItem () to the UnsortedType ADT that returns the last element in the list. The function has the following prototype:
ItemType ReturnLastItem();
Preconditions: List is initialized and not empty.
Postconditions: List is unchanged.

What is IteamType?

i think it's an unsorted list

i think it's an unsorted list

Ok.Isn't it an object? (a class)

yes a class

yes a class

Show it to us.

lol
this is torture
i have nothing
no class
no function
nothing in the exercise except what i've told u

lol
this is torture
i have nothing
no class
no function
nothing in the exercise except what i've told u

Do you have to make the class?

i guess so..it's not there so if there is something called class missing then i'll have to write it too

>this is torture
You got that right.

>i have nothing
>no class
>no function
>nothing in the exercise except what i've told u
Then you won't get much help. First, we tend to frown on people who run to us asking for "help" when they haven't done jack squat. Second, it's extremely difficult to help from the very start without doing a lot of the work for you.

If you need to write the UnsortedType ADT then you should know enough to do so with a minimum of fuss. But until that type exists, there's no way we can answer your question because the answer depends on how UnsortedType is implemented.

>this is torture
You got that right.

>i have nothing
>no class
>no function
>nothing in the exercise except what i've told u
Then you won't get much help. First, we tend to frown on people who run to us asking for "help" when they haven't done jack squat. Second, it's extremely difficult to help from the very start without doing a lot of the work for you.

If you need to write the UnsortedType ADT then you should know enough to do so with a minimum of fuss. But until that type exists, there's no way we can answer your question because the answer depends on how UnsortedType is implemented.

u dont have to be a b****..u dont want to answer then dont!!

commented: Grow up. +0

I didn't wake up this morning with the intention of being a jackass, but if you really want to see how I earned my reputation, I'll be happy to oblige.

Do your damn homework and stop trying to leech off of the kindness of others. If you want help, prove that you've done something to help yourself first. I strongly suggest that you read our rules, the announcements on this forum, and any sticky that applies to homework before posting again, because from now on I'm no longer going to give you the benefit of the doubt.

By the way, this thread is going nowhere on-topic and it's going downhill in terms of civility, so I'm closing it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.