help me in my work ....
can any one give me cods on linked stacks...
coz i faced alote of proplems...
thanxxxx

hi all....
this is my problem...
------------------------------------------
Write two different functions

\\\***\\\ Orderd_insert ( Friend and Independent Function) : Write a function that take a sorted Linked Stack and insert an element at its correct location, which keep the stack sorted.

Note: You have to solve the problem in two different ways, the first idea as Friend function and another as Independent function.

Example : If the stack initially such as Top_node -> 5 , 7, 8, 12, 15, 25, 32

After insertion( 20 ) it will be Top_node -> 5 , 7, 8, 12, 15, 20, 25, 32

i solve it ...but i have a lot of errors

Use code tags to post relevant code with error messages. The error messages should be in order of presentation by the compiler, as frequently if you fix the first error message the others go away as well.

Example : If the stack initially such as Top_node -> 5 , 7, 8, 12, 15, 25, 32

After insertion( 20 ) it will be Top_node -> 5 , 7, 8, 12, 15, 20, 25, 32

Well the logic you need is simple:

Use two stacks - one already sorted and one that is empty (called temp).

Then when you get a new element, keep on popoing element from the sorted one and push them to the other temp one as long as the new element is larger.
Once you find the correct place for the new element, push it to the sorted stack, then pop the elemnts from the other temp stack and push into the sorted one. :D

Well you got to put all this into code ofcource :cool:

Why dont you post what you have alredy written so that others can have a look :idea:

--------------------------
Programming ( Assignment / Project ) Help

This article has been dead for over six months. Start a new discussion instead.