Linked list

This is a discussion on Linked list within the C++ Programming forums, part of the General Programming Boards category; How do I correct this code? I'm getting an error message telling me that local function definitions are illegal. It ...

  1. #1
    gerald
    Guest

    Question Linked list

    How do I correct this code? I'm getting an error message telling me that local function definitions are illegal.

    It also says "end of file found before left brace." What's that?

    Code:
    node * pop (node * head)
    {    node* p=NULL;
    	 node* q =NULL;
    	 cout<<"Enter value to be deleted: ";
    	 cin>>num;
    	//cout<<"** Error  Empty Stack **"<<endl;
    	if (head->n==num)
    	{
    		p = head;
    		head=head->next;
    		delete p;
    	}
    
    	else
    	{
    		p = head;  // point to the 1st node which is going to be removed
    		q=head->next;
    		while (q!=NULL && q->n<num)
    		{
    			p=q;
    			q=q->next;
    		}
    		if (q->n==num)
    		{
    			p->next =q->next;
    			delete q;
    		}
    		else if (q==NULL || q->n>num)
    			cout<<"** Error  Value not found **"<<endl;
    	}
    	return head;
    
    }
    void print(node * head)
    {
    	node * p=NULL;
    	if (head==NULL)
    		cout<<"** Error  Empty Stack **"<<endl;
    	else
    	{
    		p = head;
    		while (p!=NULL)
    		{
    			cout<<p->n<<" ";
    			p=p->next;
    		}
    	}
    	return;
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "It also says "end of file found before left brace." What's that?"

    } <------left brace

    The compiler was expecting a left brace to match an earlier right brace, but it hit the end of the file first.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 11:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21