Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct _node{
- int data;
- struct _node *next;
- };
- typedef struct _node node;
- int main(){
- node *head, *ptr;
- head = new node;
- ptr = head; // starting point
- // initialize data value
- int n, value;
- cout << "how many struct do you need: ";
- cin >> n;
- for (int i = 0; i < n; i++){
- cout << "Please input the value for " << i+1 << " struct: " ;
- cin >> value;
- ptr->data = value;
- ptr->next = new node;
- ptr = ptr->next;
- }
- // print out
- ptr = head;
- for (int i = 0; i < n; i++){
- cout << "the value for " << i+1 << " struct: " << ptr->data << endl;
- ptr = ptr->next;
- }
- // free memory
- delete head;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement