Hello shadabrana,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Looking around I found that you have not received any response yet.
If you would have looked at the code after using code tags you would have seen that your copy and paste may have left out the closing brace '}' of the function or maybe it was not there to begin with,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
void sort()
{
if (!isEmpty())
{
int check = 0;
Process *cur = head;
do
{
cur = cur->Next;
check++;
} while (cur != head);
for (int k = 0; k < check; k++)
{
cur = head;
for (int n = 0; n < check; n++)
{
if ((cur->arrTime) > (cur->Next->arrTime))
{
string name = cur->name;
int arr = cur->arrTime, burst = cur->burstTime;
cur->name = cur->Next->name;
cur->arrTime = cur->Next->arrTime;
cur->burstTime = cur->Next->burstTime;
cur->Next->burstTime = burst;
cur->Next->arrTime = arr;
cur->Next->name = name;
cur = cur->Next; // issue here
}
else
{
cur = cur->Next;
}
}
}
}
}
|
With proper indenting it is easier to see that.
There is a good chance that you have used the line
using namespace std;
somewhere in your program file(s) and this could be a potential problem with your function "sort" as there is a function"std::sort" in the <algorithm> header file anm maybe somewhere else.
When it comes to "class", "structs" and function names I like to start the names with a capital letter to help keep it separate from a variable name or something that might be in the standard name space. Another option is to name the function something like "SortLL" or a name that is more descriptive of what the function does. For now it may be easier to start the name with a capital letter.
You say that you have an issue with line 29, but you say nothing about line 34. My question is on line 29 what does "cur->Next" actually contain?
Now that I notice it variable names are best when they start with a lower case letter. Being in a class or struct do not give regular variables any special privilege.
Right now I do not see anything with line 29 other than what "cur->Next" is. If this is not a good address then you will have a problem.
Without the rest of the program I have no way to test the function. And there might even be a better way to sort the linked list.
Hope that helps,
Andy
Edit:
I noticed line 3 which says
if(!isEmpty())
. If what is not empty. You could either have an endless loop or an if condition that is never true.