資料結構實驗之連結串列三:連結串列的逆置(SDUT 2118)
阿新 • • 發佈:2018-12-13
#include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; int main() { int n; struct node *head,*p; head = new node; head -> next = NULL; while(~scanf("%d", &n)) { if(n == -1) break; p = new node; p -> next = NULL; p -> data = n; p -> next = head -> next; head -> next = p; } for(p = head -> next ; p != NULL; p = p -> next) { if(p == head -> next) printf("%d",p->data); else printf(" %d",p->data); } printf("\n"); return 0; }