Insert - / insert.cpp / / Example of a...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// insert.cpp // Example of a dynamically-allocated linked list. / // include files #include<iostream.h> #include<iomanip.h> #include"apstring.h" # // global structure, variables, and constants / struct county_node // node for linked list { apstring county_name; long population; county_node *next; // link to next node }; county_node *head_ptr; // pointer to head of linked list county_node *current_ptr; // pointer to current node // function prototypes int get_county_data(apstring &name, long &popul); void insert_node(apstring &name, long popul); void position_insertion_point(long popul); void make_node_new_head(county_node *new_rec_ptr); void move_current_to_end(); void display_list(); void delete_list(); v // beginning of main function int main() { apstring name; long popul; if(get_county_data(name, popul)) // prompt user for data for the node { head_ptr = new county_node; // initialize list head head_ptr->county_name = name; head_ptr->population = popul; head_ptr->next = NULL; // initialize next node pointer to NULL while(get_county_data(name,popul)) { insert_node(name, popul); } display_list(); // display the counties and populations delete_list(); // free the memory used by the linked list } cout << "\nEND OF PROGRAM\n";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Insert - / insert.cpp / / Example of a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online