Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- struct Node {
- int Element;
- Node* next;
- };
- typedef Node* Position;
- typedef Node* List;
- void MakeNull_List(List *L){
- *L = NULL;
- }
- int Empty_List(List L) {
- return ( L == NULL );
- }
- int Length(List L) {
- if( Empty_List(L) ) return 0;
- Position p = L;
- int length = 0;
- while(p != NULL) {
- length++;
- p = p->next;
- }
- return length;
- }
- void Append(List *L, int data) {
- Position p = *L;
- if( Empty_List (*L) ) {
- p->Element = data;
- p->next = NULL;
- }
- while(p != NULL) {
- p = p->next;
- }
- Position temp;
- temp->Element = data;
- p->next = temp;
- temp->next = NULL;
- }
- int main(void) {
- List L;
- MakeNull_List(&L);
- if(Empty_List(L)) cout << "Empty" << endl;
- cout << "Length= " << Length(L);
- int x = 5;
- Append(L, x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement