sorting in doubly linked list

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 10

  • @freecode947
    @freecode947  4 ปีที่แล้ว +4

    #include
    #include
    struct node
    {
    int value;
    struct node *next;
    struct node *left;
    };
    struct node *newnode, *head = NULL, *temp;
    void create()
    {
    int num = 1;
    while(num)
    {
    newnode = (struct node*)malloc(sizeof(struct node));
    printf("enter new node value
    ");
    scanf("%d",&newnode->value);
    newnode->next = NULL;
    newnode->left = NULL;
    if(head == NULL)
    {
    head = newnode;
    }
    else
    {
    temp = head;
    while(temp->next != NULL)
    {
    temp = temp->next;
    }
    temp->next = newnode;
    }
    printf(" do you want to create mode node 1 for yes and 0 for no
    ");
    scanf("%d",&num);
    }
    }
    void display()
    {
    if(head == NULL)
    {
    printf("double linked list is empty
    ");
    }
    else
    {
    temp = head;
    while(temp != NULL)
    {
    printf("%d=>",temp->value);
    temp = temp->next;
    }
    }
    }
    void sort()
    {
    struct node *i, *j;
    int num;
    for(i = head; i->next != NULL; i=i->next)
    {
    for(j=i->next; j != NULL; j=j->next)
    {
    if(i->value > j->value)
    {
    num = j->value;
    j->value = i->value;
    i->value = num;
    }
    }
    }
    }
    int main()
    {
    create();
    display();
    printf("sorted doubly linked list
    ");
    sort();
    display();
    return 0;
    }

  • @snehakar1139
    @snehakar1139 3 หลายเดือนก่อน +1

    Thank you so much for the code and explanation and the execution.....................

    • @freecode947
      @freecode947  3 หลายเดือนก่อน

      You can checkout other codes too. I try to cover most of the code that was the part of Data structure and Algorithms part

    • @freecode947
      @freecode947  3 หลายเดือนก่อน

      You can also check out the project playlist section

  • @Sunil-lf1wd
    @Sunil-lf1wd ปีที่แล้ว +1

    great brother keep it up😊

    • @freecode947
      @freecode947  ปีที่แล้ว

      Thank you so much 😀

  • @558_nalinkumarsingh9
    @558_nalinkumarsingh9 2 ปีที่แล้ว +1

    Thanks