Advertisement
rickyreticent

linked list

Mar 7th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Sisip List
  2.  
  3.  
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include <malloc.h>
  7. using namespace std;
  8.  
  9. typedef struct node{
  10. int data;
  11. struct node *next;
  12. } nod, *nodptr;
  13.  
  14. void ngelist(nodptr *s){
  15. *s=NULL;
  16. }
  17.  
  18. nodptr NodNew(int x){
  19. nodptr n;
  20. n=(nodptr) malloc
  21. (sizeof (nod));
  22. if(n!=NULL){
  23. n->data=x;
  24. n->next=NULL;
  25. }
  26. return n;
  27. }
  28. void sisiplist(nodptr *s, nodptr t, nodptr p){
  29. if(p==NULL){
  30. t->next=*s;
  31. *s=t;
  32. } else {
  33. t->next=p->next;
  34. p->next=t;
  35. }
  36.  
  37. }
  38.  
  39. void cetaklist(nodptr s){
  40. nodptr ps;
  41. for (ps=s; ps!=NULL; ps=ps->next){
  42. cout<<" "<<ps->data<<"-->"<<endl;
  43. }
  44. }
  45.  
  46. int main(){
  47. nodptr pel;
  48. nodptr n;
  49. ngelist(&pel);
  50. n=NodNew(55);
  51. sisiplist(&pel,n,NULL);
  52. n=NodNew(75);
  53. sisiplist(&pel,n,NULL);
  54. n=NodNew(60);
  55. sisiplist(&pel,n,NULL);
  56. n=NodNew(20);
  57. sisiplist(&pel,n,NULL);
  58. n=NodNew(33);
  59. sisiplist(&pel,n,NULL);
  60. cetaklist(pel);
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement