0

HI ,

i have some errors about linked list,when i made print it only shows
characeters like 'ô¼'... plz help; :lol: // lets assume wordCount is 10 and
vayArray is {"lower",upper}; :cool:

Thank you very much

Here is code:

struct for_char_5
{
	char vh5[80];	for_char_5 *next;
};

for_char_5 *p,
	   *start,
	   *end;


void create_linked_list ()
{
	p=new for_char_5;
	start=p;

	for (int i=0;i<wordCount;i++)
	{
		if (strlen(vayArray[i])==5)
			strcpy((*p).vh5,vayArray[i]);
		end=p;
		p=new for_char_5;

	}
	(*end).next=NULL;
}
3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Ancient Dragon
0

there are a lot of errors in that code. For example, in a linked list, the next item is supposed to point to the next node in the list.

start->next >>> node->next >>> node->next ...

The end of the linked list is noted when next == NULL.

Your program does not set the next member, so consequently it does not create a linked list.

void create_linked_list ()
{
	start = NULL;
        end = NULL;

	for (int i=0;i<wordCount;i++)
	{
		if (strlen(vayArray[i])==5)
                {
                      p = new for_char_5;
                      p->next = NULL;
		     strcpy(p->vh5,vayArray[i]);
                     if(start == NULL)
                     {
                            start = p;
                            end = p;
                      }
                     else
                     {
                            end->next = p;
                            end = p;
                      }
                }
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.