Welcome! Log In Create A New Profile

Advanced

Assignment 01 Semester 2

Posted by S S J 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 01 Semester 2
July 16, 2010 08:44AM
Greetings all!

Needed some help with question two. My code seems to be correct but it just won't compile. I tried what we've been told in the errata on pg 31 of TL 101 but it still does't work. Could anyone help? This is the error I'm getting:

Compiler: Default compiler
Building Makefile: "C:\unisa\devcpp\Programs\Cos211\Linked List_ch_5\Makefile.win"
Executing make...
mingw32-make.exe -f "C:\unisa\devcpp\Programs\Cos211\Linked List_ch_5\Makefile.win" all
g++.exe -c Untitled4.cpp -o Untitled4.o

In file included from unorderedLinkedList.h:3,

from Untitled4.cpp:2:
LinkedListType.h:48: error: ISO C++ forbids declaration of `nodeType' with no type
LinkedListType.h:48: error: expected `;' before '<' token
LinkedListType.h:49: error: ISO C++ forbids declaration of `nodeType' with no type
LinkedListType.h:49: error: expected `;' before '<' token
LinkedListType.h:58: error: prototype for `bool linkedListType<Type>::isEmptyList() const' does not match any in class `linkedListType<Type>'
LinkedListType.h:12: error: candidate is: bool linkedListType<Type>::isEmptyList()
LinkedListType.h:58: error: template definition of non-template `bool linkedListType<Type>::isEmptyList() const'
LinkedListType.h: In member function `void linkedListType<Type>::destroyList()':
LinkedListType.h:73: error: `nodeType' undeclared (first use this function)
LinkedListType.h:73: error: (Each undeclared identifier is reported only once for each function it appears in.)
LinkedListType.h:73: error: expected primary-expression before '>' token
LinkedListType.h:73: error: `temp' undeclared (first use this function)
LinkedListType.h: In member function `void linkedListType<Type>::initializeList()':
LinkedListType.h:90: error: there are no arguments to `destroylist' that depend on a template parameter, so a declaration of `destroylist' must be available
LinkedListType.h:90: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
LinkedListType.h: In member function `void linkedListType<Type>::print() const':
LinkedListType.h:96: error: `nodeType' undeclared (first use this function)
LinkedListType.h:96: error: expected primary-expression before '>' token
LinkedListType.h:96: error: `current' undeclared (first use this function)
LinkedListType.h:101: error: `cout' undeclared (first use this function)
LinkedListType.h: At global scope:
LinkedListType.h:129: error: expected constructor, destructor, or type conversion before '<' token
LinkedListType.h:129: error: expected `;' before '<' token
LinkedListType.h:136: error: expected constructor, destructor, or type conversion before '<' token
LinkedListType.h:136: error: expected `;' before '<' token
LinkedListType.h: In member function `void linkedListType<Type>::copyList(const linkedListType<Type>&winking smiley':
LinkedListType.h:147: error: `nodeType' undeclared (first use this function)
LinkedListType.h:147: error: expected primary-expression before '>' token
LinkedListType.h:147: error: `newNode' undeclared (first use this function)
LinkedListType.h:148: error: expected primary-expression before '>' token
LinkedListType.h:148: error: `current' undeclared (first use this function)
LinkedListType.h:162: error: `otherlist' undeclared (first use this function)
LinkedListType.h:164: error: `NodeType' has not been declared
LinkedListType.h:164: error: expected primary-expression before '>' token
LinkedListType.h:164: error: expected primary-expression before ';' token
LinkedListType.h:173: error: `nodeType' has not been declared
LinkedListType.h:173: error: expected primary-expression before '>' token
LinkedListType.h:173: error: expected primary-expression before ';' token
LinkedListType.h: In member function `Type linkedListType<Type>::returnKth(int)':
LinkedListType.h:211: error: `nodeType' undeclared (first use this function)
LinkedListType.h:211: error: expected `;' before "current"

LinkedListType.h:215: error: `err' undeclared (first use this function)
LinkedListType.h:215: error: `endl' undeclared (first use this function)
LinkedListType.h:216: error: break statement not within loop or switch
LinkedListType.h:222: error: `current' undeclared (first use this function)
LinkedListType.h: In member function `void linkedListType<Type>::deleteKth(int)':
LinkedListType.h:233: error: `nodeType' undeclared (first use this function)
LinkedListType.h:233: error: expected primary-expression before '>' token
LinkedListType.h:233: error: `current' undeclared (first use this function)
LinkedListType.h:234: error: expected primary-expression before '>' token
LinkedListType.h:234: error: `trailCurrent' undeclared (first use this function)
LinkedListType.h:237: error: `cerr' undeclared (first use this function)
LinkedListType.h:237: error: `endl' undeclared (first use this function)
In file included from Untitled4.cpp:2:
unorderedLinkedList.h: At global scope:
unorderedLinkedList.h:8: error: expected `,' or `...' before "item"
unorderedLinkedList.h: In member function `bool unorderedLinkedList<Type>::search(const Type&winking smiley const':

unorderedLinkedList.h:21: error: `nodeType' undeclared (first use this function)
unorderedLinkedList.h:21: error: expected primary-expression before '>' token
unorderedLinkedList.h:21: error: `current' undeclared (first use this function)
unorderedLinkedList.h: In member function `void unorderedLinkedList<Type>::insertFirst(const Type&winking smiley':
unorderedLinkedList.h:40: error: `nodeType' undeclared (first use this function)
unorderedLinkedList.h:40: error: expected primary-expression before '>' token
unorderedLinkedList.h:40: error: `newNode' undeclared (first use this function)
unorderedLinkedList.h:41: error: `nodeType' has not been declared
unorderedLinkedList.h:41: error: expected primary-expression before '>' token
unorderedLinkedList.h:41: error: expected primary-expression before ';' token
unorderedLinkedList.h:47: error: `count' undeclared (first use this function)
unorderedLinkedList.h: At global scope:
unorderedLinkedList.h:53: error: expected init-declarator before "const"
unorderedLinkedList.h:53: error: expected `;' before "const"
unorderedLinkedList.h: In member function `void unorderedLinkedList<Type>::deleteNode(const Type&winking smiley':
unorderedLinkedList.h:78: error: `nodeType' undeclared (first use this function)
unorderedLinkedList.h:78: error: expected primary-expression before '>' token
unorderedLinkedList.h:78: error: `current' undeclared (first use this function)
unorderedLinkedList.h:79: error: expected primary-expression before '>' token
unorderedLinkedList.h:79: error: `trailCurrent' undeclared (first use this function)
unorderedLinkedList.h:83: error: `cout' undeclared (first use this function)
unorderedLinkedList.h:83: error: `endl' undeclared (first use this function)
Untitled4.cpp: In function `int main()':
Untitled4.cpp:11: error: `cout' undeclared (first use this function)
Untitled4.cpp:11: error: `endl' undeclared (first use this function)

LinkedListType.h: In constructor `linkedListType<Type>::linkedListType() [with Type = int]':
Untitled4.cpp:8: instantiated from here
LinkedListType.h:65: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:66: error: 'class linkedListType<int>' has no member named 'last'
LinkedListType.h: In member function `Type linkedListType<Type>::returnKth(int) [with Type = int]':
Untitled4.cpp:25: instantiated from here
LinkedListType.h:213: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h: In member function `void linkedListType<Type>::deleteKth(int) [with Type = int]':
Untitled4.cpp:30: instantiated from here
LinkedListType.h:236: error: 'class linkedListType<int>' has no member named 'first'

LinkedListType.h:240: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:243: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:243: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:258: error: 'class linkedListType<int>' has no member named 'last'
LinkedListType.h:259: error: 'class linkedListType<int>' has no member named 'last'
LinkedListType.h: In member function `void linkedListType<Type>::print() const [with Type = int]':

Untitled4.cpp:34: instantiated from here
LinkedListType.h:98: error: 'const class linkedListType<int>' has no member named 'first'
LinkedListType.h: In member function `void linkedListType<Type>::destroyList() [with Type = int]':
LinkedListType.h:186: instantiated from `linkedListType<Type>::~linkedListType() [with Type = int]'
Untitled4.cpp:8: instantiated from here
LinkedListType.h:75: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:77: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:78: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:78: error: 'class linkedListType<int>' has no member named 'first'
LinkedListType.h:82: error: 'class linkedListType<int>' has no member named 'last'

mingw32-make.exe: *** [Untitled4.o] Error 1

Execution terminated

Thanks in advance.
avatar Re: Assignment 01 Semester 2
July 16, 2010 05:47PM
Do you actually have a class NodeType anywhere?

If so, have you # included it?

In fact are you sure you've done all the necessary # includes?
avatar Re: Assignment 01 Semester 2
July 17, 2010 10:57PM
In line 48 of LinkedListType.h, you're using nodeType without it being defined yet.

Check that you define it as something before you use it.
Re: Assignment 01 Semester 2
July 18, 2010 05:46PM
Really appreciate the help. I did actually make the silly mistake of not defining nodeType anywhere. However, even after defining it, I still seem to be making some mistake that I can't detect. My code is still not compiling and is giving a whole list of errors.

Hereunder is the my code. I'll really appreciate any help:

Language: C++
//linkedList.h #include <iostream>     template <class Type> struct nodeType { Type info; nodeType <Type> *link; }   template <class Type> class linkedListType { public: const linkedListType<Type> & operator= (const linkedListType<Type>&);   void initializeList();   bool isEmptyList();   void print() const;   int length() const;   void destroyList();   Type front() const;   Type back() const;   Type returnKth (int kth);   void deleteKth (int kth);   virtual bool search(const Type& searchItem) const =0;   virtual void insertFirst (const Type& newItem) =0;   virtual void insertLast (const Type& newItem)=0;   virtual void deleteNode (const Type& deleteItem) =0;     linkedListType();   linkedListType (const linkedListType<Type>& otherList);   ~linkedListType ();   protected: int count; nodeType<Type> *first; nodeType<Type> *last;   private: void copyList (const linkedListType<Type>& otherList);   };     template <class Type> bool linkedListType<Type>::isEmptyList() const { return (this->first ==NULL); }   template <class Type> linkedListType<Type>::linkedListType() { this->first = NULL; this->last = NULL; this->count = 0; }   template <class Type> void linkedListType<Type>::destroyList() { nodeType<Type> *temp;   while (this->first != NULL) { temp = this->first; this->first = this->first->link; delete temp; }   this->last = NULL;   this->count = 0; }   template <class Type> void linkedListType<Type>::initializeList() { destroylist(); }   template <class Type> void linkedListType<Type>::print() const { nodeType<Type> *current;   current=this->first; while (current!=NULL) { cout << current->info<< " "; current=current->link; } }   template <class Type> int linkedListType<Type>::length() const { return count; }   template <class Type> Type linkedListType<Type>::front() const { assert (this->first !=NULL);   return (this->first->info); }   template <class Type> Type linkedListType<Type>::back () const { assert (this->last !=NULL);   return this->last->info; }   template <class Type> linkedListIterator<Type> linkedListType<Type>:: begin { linkedListIterator<Type> temp (this->first); return temp; }   template <class Type> linkedListIterator<Type> linkedListType<Type>::end { linkedListIterator<Type> temp(NULL);   return temp; }   template <class Type> void linkedListType<Type>::copyList (const linkedListType<Type>& otherList) { nodeType<Type> *newNode; nodeType<Type> *current;   if (this->first!=NULL) destroyList(); if (otherList.first == NULL) { this->first = NULL; this->last = NULL; this->count = 0; } else { current= otherList.first;   count=otherlist.count;   this->first = new NodeType<Type>; this->first->info = current->info; this->first->link= NULL; this->last= this->first; current=current->link;     while (current!=NULL) { newNode = new nodeType<Type>; newNode->info = current->info; newNode->link = NULL; this->last->link = newNode;   current = current->link; } } }   template <class Type> linkedListType<Type>::~linkedListType() { destroyList(); }   template <class Type> linkedListType<Type>::linkedListType (const linkedListType<Type>& otherList) { this->first=NULL; copyList(otherList); }   template <class Type> const linkedListType<Type>& linkedListType<Type>::operator= (const linkedListType<Type>& otherList) { if (this!=&otherList) { copyList(otherList); } return*this; }   template <class Type> Type linkedListType<Type>:: returnKth (int kth) { nodeType current= this->first; int cnt = 0; if ((kth>count) || (this->first == NULL)) { err<<"The " << kth << "th element does not exist in this list!"<<endl; break; } else { while (cnt < kth) { current=current->link; cnt ++; } if (cnt == kth) return current->info; } }   template <class Type> void linkedListType<Type>:: deleteKth (int kth) { nodeType<Type> *current; nodeType<Type> *trailCurrent; int cnt=1; if ((this->first==NULL)||(kth>count)) cerr<< "The "<< kth << "th does not exist!"<< endl; else { current=this->first; if (kth==1) { this->first = this->first->link; delete current; this->count --; } else { while (cnt < kth) { trailCurrent=current; current = current->link; cnt ++; } if (cnt == kth) { trailCurrent->link = current->link; if (current == this->last) this->last = trailCurrent;   delete current; } this->count--; } }   }//end linkedList.h

Language: C++
//unorderedLinkedList.h #ifndef H_unorderedLinkedList #define H_unorderedLinkedList #include "LinkedListType.h" template <class Type> class unorderedLinkedList: public linkedListType<Type> { public: bool search (const Type& search item) const;   void insertFirst (const Type& newItem);   void insertLast (const Type& newItem);   void deleteNode (const Type& deleteItem); };   template <class Type> bool unorderedLinkedList<Type>:: search(const Type& searchItem) const { nodeType<Type> *current; bool found=false;   current = this->first;   while (current != NULL && !found) { if (current->info == searchItem) found = true; else current= current->link; return found; }   }   template<class Type> void unorderedLinkedList<Type> :: insertFirst(const Type& newItem) { nodeType<Type> *newNode; newNode = new nodeType<Type>;   newNode->info=newItem; newNode->link= this->first;   this->first = newNode; count++; if (this->last==NULL) this->last=newNode; }   template <class Type> void unorderedLinkedList<Type> :: insertLast const Type& newItem) { nodeType<Type> *newNode;   newNode=new nodeType<Type>;   newNode->info=newItem; newNode->link=NULL;   if (this->first == NULL) { this->first=newNode; this->last=newNode; this->count++; } else { this->last=newNode; this->count++; } }   template <class Type> void unorderedLinkedList<Type>:: deleteNode (const Type& deleteItem) { nodeType<Type> *current; nodeType<Type> *trailCurrent; bool found=false;   if (this->first == NULL) cout<< "The list is empty!"<<endl; else { if (this->first->info==deleteItem) { current=this->first; this->first=this->first->link; this->count--;   if (this->first==NULL) this->last=NULL; delete current; } else { found = false; trailCurrent=this->first;   current=this->first->link;   while (current!=NULL && !found) { if (current->info != deleteItem) { trailCurrent=current; current=current->link; } else found = true; }   if (found) { trailCurrent->link=current->link; this->count--;   if (this->last==current) this->last = trailCurrent; delete current; }   else cout<<"The item to be deleted is not in the list!"<< endl; } } } #endif//end unorderedLinkedList.h

Language: C++
//LinkedListTest.cpp #include <iostream> #include "unorderedLinkedList.h"   using namespace std;   int main () { unorderedLinkedList<int> list1; int num, kthOutput, kthDelete;   cout << "Enter Numbers ending with '-1' " << endl;   cin >> num; while (num != -1) { list1.insertLast(num); cin >> num; }   cout << endl;   cout << "Enter the number of the element you wish to be output: "<<endl; cin >> kthOutput;   cout<< list1.returnKth(kthOutput);   cout << "Enter the number of the element you wish to be output: "<<endl; cin >> kthDelete;   list1.deleteKth(kthDelete);   cout << "The list after the " << kthDelete << "th item was deleted is: " <<endl;   list1.print();   cout<< endl;   return 0;   }//end LinkedListTest.cpp
avatar Re: Assignment 01 Semester 2
July 18, 2010 06:29PM
I hope you copy/pasted this. You should also always include the first 5-10 lines of the error messages since they usually help in diagnosing the problem.

What I did see is a syntax error for your struct. Like class definitions, they need to be terminated with a semi-colon. Yours doesn't have one.
Re: Assignment 01 Semester 2
July 22, 2010 03:44AM
Thanks.
Yes, I did copy /paste the above code. I then carefully went through the entire error log and was able to figure out almost all the errors, praise be to God.
There were a whole lot of very silly syntax errors. Anyway, now my programme is compiling, but it won't run. The dos screen just flashes for a second when I try to run it. This is happening in both vista and XP.

Furthermore, could anyone kindly comment on my functions returnKth and deleteKth (The first is meant to return the kth element of a linked list and the second is meant to delete the kth element in a linked list.) and my testing programme. Are they correct and efficient?

Thanks in advance
avatar Re: Assignment 01 Semester 2
July 22, 2010 10:57AM
You can put a pause in your program (using the word 'pause', I think), so that it doesn't wipe itself off the screen once its finished executing. You'd have to google on "pause .. etc" to get the details. What's happening is the program is doing everything you told it to do (without error) and then getting to the end, returning you a zero; and then it's done. No longer required. So it knocks off. Goes home.

I think if you run from inside a command line window you don't get this problem. If I recall correctly it's a GUI issue.
Re: Assignment 01 Semester 2
July 22, 2010 01:06PM
The code is

Language: C++
system("pause");
but it's very resource intensive. I prefer to just put

Language: C++
cin.get();
it waits for a return and doesn't reach out to the system for such a small command. Just add it to the end of your main function and all will be well.

Chris Botha

=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt
Re: Assignment 01 Semester 2
July 22, 2010 01:11PM
Does this happen when you compile and run the program as a standalone app or when you run through build and run through the IDE?

Chris Botha

=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt
avatar Re: Assignment 01 Semester 2
July 22, 2010 01:57PM
Have a look at the path of the *.exe that was created.
If there are spaces in the path then you can betcha that this would have caused the problem(flashing of the screen)
Hope this helps
smile
avatar Re: Assignment 01 Semester 2
July 22, 2010 04:21PM
@S S J:
Your insert and delete functions look alright. At first glance, they look like O(n) functions which is about as good as you're going to get with a linked list. If your program needs anything faster, you would rather use a hash table, which is O(1).

@Wiseguy:
If it runs and flashes, it's working perfectly, there's nothing wrong with the spaces in the name.

@slow_eddy & Chris:
Windows flashing are not an error, bug, or issue. There's nothing wrong with the program at all, either the one you wrote, or the IDE. Putting in cin.get() or system("pause"winking smiley is a hack or a kludge.

I see people complaining about this year after year, semester after semester. The problem is not with anything on the computer, but with your idea of what should be happening and a misunderstanding with the differences between the two types of programs that can be run.

The two types of programs are console and GUI. I wish the lecturers would devote tut letter to the differences between the two because only people who have experience in the pre-Windows 95 days will understand the difference. Most young people coming into these courses have only had experience of GUI applications.

For reasons of complexity, it's better to leave GUI programming to later years (COS214 & COS311) and focus on learning the basics of programming before tackling the intricacies of the operating system.

In the old days, console applications were the norm and GUI apps the super-cool things. The computers didn't start up with fancy pictures and mouse cursors, they started with a black screen with a flashing underscore. You had to type your commands in. This is what is referred to as a console and this is where all the COS111, COS112, COS211 programs should be run from.

To open up a console window, you run cmd.exe in windows (XP or later). The window will stay open till you either close the window, or you type in exit. You should be testing your applications by typing in the application name and pressing enter. You will see that your application will run and display any messages you told it to display, then it will return to the command prompt and wait for your next instruction. This is precisely why your windows flash before your eyes when you try to run them from the IDE.

What happens is that the Operating system sees that you are trying to run a console application as a separate process. Since the IDE is in a GUI window, it cannot handle a console applications input and output. The operating system spawns a console window and starts executing the application. Most applications for these courses are designed to either answer a few questions and/or display some output, then end. This happens extremely quickly on modern computers so the program ends almost as quickly as it started. Since the operating system sees that the program has quit, the console window is no longer needed so it closes it down.

If you run the application from a console window you opened yourself, the window won't close.

@Chris
It is true that the system("pause"winking smiley is technically extravagant with resources but I wouldn't call it intensive unless you're running on an XT with 540KB of RAM. I would not recommend using it though for other reasons. The main one is portability.

What the system function actually does is pause your program, create another process and execute whatever console command you supplied in the parameter. You could, for instance, put in system("notepad.exe"winking smiley and notepad will open up. The "pause" part is actually a system command - that you can run from the console directly if you like - but only on microsoft operating systems. It doesn't exist on Linux, for example. Thus, if you use it, you're restricting your code to the NT console.
avatar Re: Assignment 01 Semester 2
July 22, 2010 07:14PM
Thanks roban... I am now chastised and contrite. I knew pause was a kludge, but had no idea just how ugly it was. Yes, running the programs in a console is the way to go. (And if I somehow forget that, hopefully I can remember to cin.get() instead. )
avatar Re: Assignment 01 Semester 2
July 22, 2010 07:51PM
I didn't mean for you to feel chastised.

I just don't know why the lecturers continue to ignore this issue. Watch the fora for COS111 COS112 and COS211. At the start of every year, or semester now they're semesterised, there's always a number of people posting queries about the console flashing by.

I wish the lecturers would address this. It's been happening for years.
avatar Re: Assignment 01 Semester 2
July 22, 2010 08:55PM
Let me rephrase that somewhat:

smile
smile

Actually as far as I'm concerned it is perfectly good and proper to castigate the perpetrators of kludges and hacks remorselessly. I suppose that's why I feel that way.

smile

ie. Your posting was exactly just the way it should've been. And tough luck to those of us whose consciences are stung by the truth. In fact, I reckon you're actually much, much too kind.
Re: Assignment 01 Semester 2
July 24, 2010 08:29PM
Thanks all for the beneficial input.

I have figured out a way of running the program without the flashing problem: I run the exe file directly as 'administrator' in vista. I was not able to run it directly from the cmd.exe that Roban suggested as regretfully I am not aware of the command language. However, my program is still not running through to the end. An error causes it to close after entering the numbers of the linked list and requesting the user to enter the number of the element to be output.
Thanks
Re: Assignment 01 Semester 2
August 12, 2010 12:00PM
Hey guys, I'm busy on this question, and my program works, but when I insert 3 data values, and I say find the 4th data value, nothing happens..then after awhile windows give me an error message, but when I ask for the 5th data value, my program terminates just fine.

Why would this be?

_______________________________________
Don't be different...be the one making a difference
avatar Re: Assignment 01 Semester 2
August 13, 2010 10:20AM
When posting a message about a problem that includes an error message, it usually is a lot easier to find a solution if you include said error message with your post.
Re: Assignment 01 Semester 2
August 13, 2010 02:03PM
Sure thanks...will do that in future. Got my program to run just fine.

_______________________________________
Don't be different...be the one making a difference
Re: Assignment 01 Semester 2
August 17, 2010 10:08AM
BlaXpydo Wrote:
-------------------------------------------------------
> Hey guys, I'm busy on this question, and my
> program works, but when I insert 3 data values,
> and I say find the 4th data value, nothing
> happens..then after awhile windows give me an
> error message, but when I ask for the 5th data
> value, my program terminates just fine.
>
> Why would this be?


I'm having the same issue. Any hints on where I should look for a solution? Basically I'm testing the required node position against the length of the list, and if it's greater, I'm using exit(1) to terminate. As with the above post, this works for higher values, but if it's just 1 value higher, I get a windows error message first, and then when I cancel the message, it seems to terminate as required.
Re: Assignment 01 Semester 2
August 17, 2010 10:34AM
Rbuys Wrote:
-------------------------------------------------------
> BlaXpydo Wrote:
> --------------------------------------------------
> -----
> > Hey guys, I'm busy on this question, and my
> > program works, but when I insert 3 data values,
> > and I say find the 4th data value, nothing
> > happens..then after awhile windows give me an
> > error message, but when I ask for the 5th data
> > value, my program terminates just fine.
> >
> > Why would this be?
>
>
> I'm having the same issue. Any hints on where I
> should look for a solution? Basically I'm testing
> the required node position against the length of
> the list, and if it's greater, I'm using exit(1)
> to terminate. As with the above post, this works
> for higher values, but if it's just 1 value
> higher, I get a windows error message first, and
> then when I cancel the message, it seems to
> terminate as required.


Found it! Marking of nodes starts from 0, not 1....
avatar Re: Assignment 01 Semester 2
August 17, 2010 11:31AM
Ahh, the infamous Out-By-One error. It's a bastard. It will rear it's ugly head many times again.
Sorry, only registered users may post in this forum.

Click here to login