so i would insert the first number in the head outside of the insertion function. Then in the insertion function it would take that head in, then add more numbers to the list until 0 is entered. is this the order?
so i would insert the first number in the head outside of the insertion function. Then in the insertion function it would take that head in, then add more numbers to the list until 0 is entered. is this the order?
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
ok, i think i get that. for the sort, how would i get it repeat itself ?
Code:do { cout << "Please insert the first number : " ; cin >> number ; insertion(HeadPtr, number); } while (number!=0);
Yes, that looks good.
As to sorting, you need an outer loop and an inner loop. In the outer loop, you just set up the pointer to the start of the list. In the inner loop, you swap items that are out of order and move to the next item. The inner loop ends when you have gone through the list completely. The outer loop ends when you haven't swapped anything [which means that all items are in order].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I know this is getting repetitive. Pretty ridiculous, i need a Live breathing teacher, If anyone is out there PLEASE pm me. I am willing to pay you for your time. Me paying you will save me money actually. I am not sure on the rules of the website about asking for help, im very desperateactually. have 2 assignments and a final in about 3 weeks. and still dont see everything the book is trying to teach, and the online teacher doesnt clarify.
anyway,
My program is falling apart. I'm talking very bad. i scrapped the whole thing because i had to change the insertion.
The goal of what i am looking to do is one thing, then i can move on to something else .
Insert a number in if the HeadPtr is empty or NULL.
I've tried
if (HeadPtr==NULL)
{
do something;
}
and
if (HeadPtr==0)
{
do something;
}
what is it that is needed to get to the inside of the if statement?
this is the whole program i am starting over with.
Code:#include <iostream> using namespace std; /* Recursive functions insertion retrieval pointer based sorted linked list of integers also if 0 is entered it keeps inserting until 0 is entered. */ struct node { int item; node *next; }; // takes in the head pointer // item to be inserted //building the list here void insertion(node *HeadPtr, int NumberToInsert) { if (HeadPtr=NULL) //If the HeadPtr is empty insert the number { HeadPtr->item=NumberToInsert; cout << "The HeadPtr->item is : " << HeadPtr->item << endl; } //end if } void traverser (node *HeadPtr) { cout << "Using Traverser the HeadPtr->item is :" << HeadPtr->item << endl; } int main() { int number; node *HeadPtr=new node; HeadPtr==NULL; while (number!=0) { cout << "Please insert the first number: "; cin >> number; } insertion( HeadPtr, number); //traverser(HeadPtr); system("pause"); return 0; }
If you don't learn to indent your code, as you've already been asked to, then I wont be reading it, and neither will a lot of other people.
It's like closing your eyes and saying "I can't see the bug!".
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Since i am not hearing or understanding anything, I am going to start from scratch. I am aware there are pretty talented people on this site. If it takes me making myself look very ignorant to learn something, so be it. I don't now what questions to aks and how to ask them, so i will a question worded a few times.
So is the book grammer different than actually grammer used?
indent....is it?
Code:function() { something; } or function() { something; } or is it function () { something }
Last edited by Emeighty; 09-09-2008 at 01:24 AM.