473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

error in location

11
i have this problem
i insert 10 as first location then 20 and 30
when i run the program it give me error in location
10 30 20

the error may be in insert can you give me hints for this
thank you in advance

Expand|Select|Wrap|Line Numbers
  1.  Node * List::InsertNode (int index , double x)
  2.  {                
  3.                       if (index < 0 )return NULL;
  4.                       int currlndex = 1 ;
  5.                       Node* currNode = head;
  6.                       while (currNode!= NULL && index > currlndex ) 
  7.                       {
  8.                             currNode;
  9.                             currlndex++;
  10.                        }
  11.                             if (index > 0 && currNode == NULL ) return NULL;
  12.                             Node*newNode = new Node;
  13.                             newNode -> data = x;
  14.                             if (index ==0)
  15.                             {
  16.                                    newNode -> next = head;
  17.                                   head = newNode;
  18.                                    }
  19.  
  20.  
  21.                             else
  22.                                            {
  23.                                            newNode -> next = currNode->next;
  24.                                            currNode->next = newNode ;
  25.                                            }
  26.                                            return newNode;
  27.     } 
  28.  
Apr 11 '15 #1

✓ answered by weaknessforcats

Usually, the first node of a list is index 0. So 10 20 30 would be indexes 0 1 and 2. It's done this way so the list works like an array, which everyone is familiar with.

Next, in what order did you enter your values? If you went 10,20,30 the all you need is append at end of list. But if you went 20 30 10 and you want to keep the list sorted then you need an insert node A before node B. That is usually a function:

Expand|Select|Wrap|Line Numbers
  1. void insertbefore(Node*A, Node* B);
where A is inserted before B.

1 1597
weaknessforcats
9,208 Expert Mod 8TB
Usually, the first node of a list is index 0. So 10 20 30 would be indexes 0 1 and 2. It's done this way so the list works like an array, which everyone is familiar with.

Next, in what order did you enter your values? If you went 10,20,30 the all you need is append at end of list. But if you went 20 30 10 and you want to keep the list sorted then you need an insert node A before node B. That is usually a function:

Expand|Select|Wrap|Line Numbers
  1. void insertbefore(Node*A, Node* B);
where A is inserted before B.
Apr 11 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: | last post by:
I am accessing the same error-containing ASP page on an ISP server using w2k IE6 but with different effect. On the first computer I get several line of HTML outputed by ASP, shown correctly by...
1
by: Matt | last post by:
I run the xalan-java v2.60 command line: java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -out test.html But it has the following error: (Location of error unknown)XSLT Error...
2
by: Sukh | last post by:
Hi, I am working on a form page (asp.net + c#). form is too long and in some cases we are validating it server side, if there is some invalid data in text box then form return from server side and...
16
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project -...
1
by: Kenny Ho | last post by:
Hi, I have written the following schema that contains the XML signature: ----------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8" ?>...
3
by: shapper | last post by:
Hello, How to load a XML document and display it immediately after in the browser? Dim doc As New System.Xml.XmlDocument doc.Load("~/XMLFile.xml") Context.Response.ContentType = "text/xml;...
3
jhardman
by: jhardman | last post by:
I was in the middle of troubleshooting a different problem when my web service stopped working with a very cryptic error message: "specified cast is not valid" The only location info is that the...
25
by: premprakashbhati | last post by:
i want to have checkboxes in my gridview ...by checking it ,i can delete the row/rows.... so i have written code and got 2 Errors ...can anyone solve it... Error:1...'gridview.RetrieveItems()': not...
11
by: xenoix | last post by:
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource. My PC :- Visual Studio 2005 .NET Framework 2 Component Factory Krypton...
4
pradeepjain
by: pradeepjain | last post by:
Hii ..i am a lamp professional!! i use javascript for validation purposes! but sometimes javascript stops working bcos of errors!!and i find it difficult to find those errors! is there any log for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.