how do i construct a list og edges then..i looked at the linked list library but then i got confused with qvector aswell..which one do i use?
how do i construct a list og edges then..i looked at the linked list library but then i got confused with qvector aswell..which one do i use?
It depends. You can add items to the list faster, but accessing elements randomly is much slower than in vector. If you plan to add a lot of items and you will only read the whole list at once, you should use linked list. If you will access single items, you should use a vector. There is also a QList which is something between linked list and a vector.Originally Posted by therealjag
hey again i was thinking of using an array of structs where my struct would be:
struct Link{
int n1;
int n2;
int capacity
}
how would i create an array of this??
no offense, but you really ought to learn some basics of data structures. there's no point in learning qt data-structures without knowing basic DS theory.
it is a bit like learning to use the harpoon, without knowing what a whale is
grab a text book on data-structures; trust me, it will go a long way to ease programming.
yeah you're probably right but its a project im doing and i dont have much time to do it which is why i havent gone about it the proper way. i guess in the summer i could read to my hearts content and not bother you guys all the timeno offense, but you really ought to learn some basics of data structures. there's no point in learning qt data-structures without knowing basic DS theory.
it is a bit like learning to use the harpoon, without knowing what a whale is
hey there i tried using the QVector to make my struct into an array but the program crashes when i try to run it. it compiles ok but there seems to be a problem with the way i am referencing the QVector...heres my code below:
Qt Code:
tr("enter second node to link:"), 25, 0, 100, 1, &ok); if(ok) integerLabel->setText(tr("%1").arg(links[0].n2));To copy to clipboard, switch view to plain text mode
any help would be much appreciated again
void QVector::append ( const T & value )
Inserts value at the end of the vector.
hey there i tried .append() but it still didnt work. i get an error saying:
i tried it with the following piece of code:"not enough contextual info to determine type"
Qt Code:
links.capacity.append(topology[n1][n2]);To copy to clipboard, switch view to plain text mode
what am i doing wrong?
What types do the links and links.capacity have?Originally Posted by therealjag
links is just my struct Link and it contains the integer which is called capacity..
my struct is shown below:
the 2-d array is just an integer as wellQt Code:
struct Link{ int n1; int n2; int capacity; }To copy to clipboard, switch view to plain text mode
int doesn't have an append() method. You probably wanted to invoke that method on some other object.
ok, so how do i add that number from topology[n1][n2] to link.capacity? i also tried insert() with my code instead of append and it still didnt work??int doesn't have an append() method.
What do you mean by "add"? capacity in an integer and it can hold only one value. You should create a list or vector and add values to it.Originally Posted by therealjag
oh sorry i was a bit unclear i just want the value at capacity[n1][n2] to be equal to one of the instances in my vector 'links' and i want it to be stored into link.capacity?What do you mean by "add"? capacity in an integer and it can hold only one value. You should create a list or vector and add values to it.
Bookmarks