problem, dodawanie elemetnu do listy jednokierunkowej

0

Poniżej wstawiam kod. Program sie kompiluje. Ale przy wywołaniu pliku a.out wyskakuje błąd fregmentation fault (core dumped). Doczytałem, że problem jest ze niewłaściwym wskaźnikiem ale nie mam pojecia gdzie. Z góry dzięki za pomoc.

 
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include "funkcje.hpp"
using namespace std; 
lista *head;
void tworzenielisty(int n)
	{
	head = NULL;
	int *nowa = new int[n];	
	for (int t=0;t<n;n++)
		{
			nowa[t]=(rand() % (10*n) + (n*n));	
		}
	for (int g=0;g<n;g++)
	    {
		lista * p = new lista;
		if (head==NULL)
		{
		p->data=nowa[g];
		p->next=NULL;
		head=p;
		cout<<"yolo";
		}
		else
		{
		p->data = nowa[g];
		p->next = head;
		head = p;
		}
		}
	}
void wyswietlenielisty()
{
	lista *t;
	t=head;
	while(t->next!=NULL)
	{
		cout<<t->data;
		t=t->next;
	}
}
0

Tak na pierwszy rzut oka to

for (int t = 0; t < n; ++t) { // zamiast ++n
	nowa[t]=(rand() % (10*n) + (n*n));  
}

Poza tym funkcja wyswietlenielisty() nie pokaże Ci ostatniego elementu; polecam również http://format.krzaq.cc/

1 użytkowników online, w tym zalogowanych: 0, gości: 1