d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help Please C++/structs
Add Reply New Topic New Poll
Member
Posts: 65
Joined: Sep 17 2013
Gold: 0.00
Nov 3 2013 05:43pm
create a linked list of Rectangles by reading data from file.
each line of this file contains the initial data for one rectangle in the order:
xc yc width height xvel yvel
I have the file of numbers.
have to build the list by adding new rectangles to the front of the list.
also, heres the struct im using.
struct rect {
int xc, yc; // upper left corner
int width, height;
int xvel, yvel; // direction ‘vector’
rect *next;
};

This post was edited by xCannon3 on Nov 3 2013 05:45pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 3 2013 05:44pm
Quote
Need Help Please C++/structs


what do you need help with exactly?
Member
Posts: 65
Joined: Sep 17 2013
Gold: 0.00
Nov 3 2013 05:46pm
Building the linked list

This post was edited by xCannon3 on Nov 3 2013 05:46pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 3 2013 05:53pm
Quote (xCannon3 @ Nov 3 2013 07:46pm)
Building the linked list


create two rectangles. set rect1.next = rect2

repeat until all rectangles are connected

This post was edited by carteblanche on Nov 3 2013 05:53pm
Member
Posts: 65
Joined: Sep 17 2013
Gold: 0.00
Nov 3 2013 05:56pm
Yeah...except there are 46. Lol.
Need to basiccally create new rect and connect them while read in the info from the file. Bit i forgot how,
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 3 2013 06:16pm
Quote (xCannon3 @ Nov 3 2013 07:56pm)
Yeah...except there are 46. Lol.
Need to basiccally create new rect and connect them while read in the info from the file. Bit i forgot how,


http://www.cplusplus.com/doc/tutorial/control/
http://www.cplusplus.com/doc/tutorial/files/
Member
Posts: 65
Joined: Sep 17 2013
Gold: 0.00
Nov 3 2013 06:36pm
Quote (carteblanche @ Nov 3 2013 08:16pm)


No, as is i forget how to create a list of rect's with using the new function so they will be connected
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 3 2013 08:37pm
Quote (xCannon3 @ Nov 3 2013 08:36pm)
No, as is i forget how to create a list of rect's with using the new function so they will be connected


rect1.next = rect2

or

rect1->next = rect2

i forget the c++ syntax. you dont have to connect them right when you're creating them.
Member
Posts: 237
Joined: Aug 6 2011
Gold: 6,026.00
Nov 7 2013 03:01pm
std::map
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll