Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. struct Node {
  8. int Element;
  9. Node* next;
  10. };
  11.  
  12. typedef Node* Position;
  13. typedef Node* List;
  14.  
  15. void MakeNull_List(List *L){
  16. *L = NULL;
  17. }
  18.  
  19. int Empty_List(List L) {
  20. return ( L == NULL );
  21. }
  22. int Length(List L) {
  23. if( Empty_List(L) ) return 0;
  24. Position p = L;
  25. int length = 0;
  26. while(p != NULL) {
  27. length++;
  28. p = p->next;
  29. }
  30. return length;
  31. }
  32.  
  33. void Append(List *L, int data) {
  34. Position p = *L;
  35. if( Empty_List (*L) ) {
  36. p->Element = data;
  37. p->next = NULL;
  38. }
  39. while(p != NULL) {
  40. p = p->next;
  41. }
  42. Position temp;
  43. temp->Element = data;
  44. p->next = temp;
  45. temp->next = NULL;
  46. }
  47.  
  48. int main(void) {
  49. List L;
  50. MakeNull_List(&L);
  51. if(Empty_List(L)) cout << "Empty" << endl;
  52. cout << "Length= " << Length(L);
  53. int x = 5;
  54. Append(L, x);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement