int main(void) { Car* head = NULL; head = insertCar(head, "Chevy", "Impala", 2014); head = insertCar(head, "Ford", "Torus", 1999); head = insertCar(head, "BMW", "Z3", 2007); printCars(head); freeCars(head); }
int main() { Car c[3]; int i=0; for(i=0; i<3; i++) getCars(&c[i]); printCars(&c[0],3); return 0; }
int main() { trainCar *root; // This will be the unchanging first node trainCar *position; // Will point to each node root = new trainCar; // Now root points to a node struct root->next = 0; // The node root points to has its next pointer // set equal to a null pointer root->name = "engine"; // By using the -> operator, you can modify the node // a pointer (root in this case) points to. position = root; if (position->next != 0) { while (position->next != 0) { position = position->next; } } // We're at the end // we'll add a new car at the end //std::cout << "How many cars (including the caboose) should we add? " << std::endl; int cars_to_add=10; //std::cin >> cars_to_add; for (int x = 1; x <= cars_to_add; x++) { position->next = new trainCar; position = position->next; position->next = 0; if (x < cars_to_add) { position->name = "This is the car #" + std::to_string(x); } else { position->name = "Caboose"; } } // Let's insert a new car insertCar(5, root, "Dining Car"); insertCar(2, root, "luggage car"); insertCar(12, root, "New Caboose 1"); insertCar(13, root, "New Caboose 2"); position = root; printCars(root); system("Pause"); }