GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jul-2004, 10:47
silicon silicon is offline
New Member
 
Join Date: Jul 2004
Posts: 13
silicon is on a distinguished road

Linked List


Hello all, I have almost completed a program that will take 8 numbers from a user and store it in a linked list. Once that is done It will ask for another entry and determine the location of this new entry and how many items are currently bigger than the new entry. I have (pretty much") 95% of it written out but am having problems with my header file (below). I just have to modify my main.cpp file to complete the program but am having problems in the header where I'm getting errors in the codeLL function. I cannot figure out why it keeps giving off this error. I thought I had written everything correctly. Please let me know if you have any suggestions or if you see something that Im just not seeing

Thanks in advance

--------------------Configuration: Linked List Main - Win32 Debug--------------------
Compiling...
Linked List Main.cpp
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(29) : warning C4183: 'deleteLL': member function definition looks like a ctor, but name does not match enclosing class
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : error C2063: 'copyLL' : not a function
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : error C2040: 'copyLL' : 'class LinkedList<DataType>::Node *(class LinkedList<DataType>::Node *)' differs in levels of indirection from 'int'
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : fatal error C1903: unable to recover from previous error(s); stopping compilation
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
Error executing cl.exe.

Linked List Main.obj - 3 error(s), 1 warning(s)


CPP / C++ / C Code:
#ifndef LINKEDLIST
#define LINKEDLIST
#include<iostream.h>

template<typename DataType>
class LinkedList
{
	private:
		class Node
		{
		public:          // Makes it accessible (public) by class Node
			DataType data;
			Node *next;
		};

		Node *first;
		int mySize;

		LinkedList::deleteLL()
		{
			Node *tempP=first, *disposeP;
			while (tempP!=0)
			{
				disposeP=tempP;
				tempP=tempP->next;
				delete disposeP;
			}
			return;
		}

		Node* LinkedList::copyLL(Node* source)
		{
			if (source==0)
				return 0;
			Node* newH=new Node;
			Node *tempP=newH;
			newH->data=source->data;
			source=source->next;
			while (source!=0)
			{
				tempP->next=newNode;
				tempP->data=source->data
					tempP=tempP->next;
				source=source->next;
			}
			temp->next=0;
			return newH;
		}

		public:
			LinkedList::LinkedList()
			{
				mySize=0;
				first=0;
			}
			LinkedList::~LinkedList()
			{
				deleteLL();
			}

			LinkedList::LinkedList( const LinkedList &source)
			{
				mySize=source.first;
				first=copyLL(source.first);
			}

			LinkedList& LinkedList::operator=(const LinkedList& s)
			{
				if (this!=&s)
				{
					deleteLL();
					mySize=s.mySize;
					first=copyLL(s.first)
				}
				return *this;
			}
				bool LinkedList::empty()
				{
					return (first==0);
				}
				void LinkedList::insert(DataType item, unsigned pos)
				{
					if (pos>mySize+1)
					{
						cout<<"Illegal position to insert:"<<pos<<endl;
						return;
					}
					mySize++
						Node* newNode=newNode;
					newNode->data=item;
					Node* prev=first;
					for (int i=1, i<pos, i++)
						prev=prev->next;
					newNode->next=prev->next;
					prev->next=newNode;
				}
				void LinkedList::delete (dataType item)
				{
					mySize--;
					Node* tempP=first;
					Node* prev=0;
					while (tempP!=0 && tempP->data!=item)
					{
						prev=tempP;
						tempP=tempP->next;
					}
					if (tempP!=0 && tempP->data==item)
					{
						prev->next=tempP->next;
						delete tempP;
					}
						else
							cout<<"Item to delete not found"<<endl;
						return;
				}

				int LinkedList::locate(DataType item)
				{
					int position=0;
					Node* ptr=first;
					while(ptr->data<item &&ptr!=0)
					{
						position++;
						ptr=ptr->next;
					}
					return position
				}

						void LinkedList::traverse()
						{
							Node *temp=first;
							while (tempP!=0)
							{
								Process(tempP->data);
								tempP=tempP->next;
							}
							return;
						}
				};
#endif

Last edited by LuciWiz : 25-Mar-2006 at 12:42. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 21-Jul-2004, 10:48
silicon silicon is offline
New Member
 
Join Date: Jul 2004
Posts: 13
silicon is on a distinguished road

Linked List Main


Hi I've included a basic main which I am using to test the header file

Code:
#include "LinkedList.h" #include<string> using namespace std; main() { }
  #3  
Old 22-Jul-2004, 04:29
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
See how you get on with my compilers error messages:
Code:
LinkedList.h:20: ANSI C++ forbids declaration `deleteLL' with no type LinkedList.h:97: syntax error before `delete' LinkedList.h:100: invalid use of member `LinkedList<DataType>::first' LinkedList.h:100: ANSI C++ forbids initialization of member `tempP' LinkedList.h:100: making `tempP' static LinkedList.h:101: ANSI C++ forbids initialization of member `prev' LinkedList.h:101: making `prev' static LinkedList.h:102: syntax error before `while' LinkedList.h:105: ANSI C++ forbids declaration `tempP' with no type LinkedList.h:105: ANSI C++ forbids initialization of member `tempP' LinkedList.h:105: making `tempP' static LinkedList.h:105: ANSI C++ forbids in-class initialization of non-const static member `tempP' LinkedList.h:105: declaration of `int LinkedList<DataType>::tempP' LinkedList.h:100: conflicts with previous declaration `class LinkedList<DataType>::Node * LinkedList<DataType>::tempP' LinkedList.h:107: syntax error before `if' LinkedList.h:117: semicolon missing after declaration of `LinkedList<DataType>' LinkedList.h: In method `class LinkedList<DataType>::Node * LinkedList<DataType>::copyLL(LinkedList<DataType>::Node *)': LinkedList.h:43: syntax error before `=' LinkedList.h: In method `class LinkedList<DataType> & LinkedList<DataType>::operator =(const LinkedList<DataType> &)': LinkedList.h:74: syntax error before `}' LinkedList.h: In method `void LinkedList<DataType>::insert(DataType, unsigned int)': LinkedList.h:89: syntax error before `*' LinkedList.h:92: syntax error before `)' LinkedList.h:95: syntax error before `;' LinkedList.h:127: syntax error before `}' LinkedList.h:130: syntax error before `{' LinkedList.h: At top level: LinkedList.h:139: parse error at end of saved function text LinkedList.h:139: confused by earlier errors, bailing out
Fixing the first error you get often clarifies things further on. Some pointers.
  • First you forgot to give a return type for deleteLL().
  • Next 'delete' is an operator in C++, you shouldn't have a function or variable with this name. This gives all those static errors as above. The compiler doesn't recognise we're making a function, so sees implicit declarations outside of any structure, not good programming.
  • C++ is case sensitive for everything. 'datatype' is not the same as 'DataType'
  • Mind your semicolons.
  • Get the syntax of your for loop out correctly.
I've not gone over your logic, I just altered it so that it compiled correctly. Hope this helps,
GF
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge sort on a linked list Temujin_12 C++ Forum 1 06-Mar-2008 21:33
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13
testing word file "need help" alexandro C Programming Language 2 03-Jun-2004 15:38
help on linked lists any1????? nick4 C Programming Language 1 17-May-2004 10:32
[include] list1.h -- Linked list class dsmith C Programming Language 2 04-May-2004 10:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:01.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.