#include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node* next;
};
void add(struct node** tail, int val) {
    struct node* temp = malloc(sizeof(struct node));
    if(*tail == NULL) {
        temp->data = val;
        temp->next = temp;
        *tail = temp;
    } else {
        temp->data = val;
        temp->next = (*tail)->next;
        (*tail)->next = temp;
    }
}
void disp(struct node* tail) {
   if(tail == NULL)
     printf("NULL");
   else {
       struct node* p = tail->next;
       do {
           printf("%d", p->data);
           p = p->next;
       }while(p!=tail->next);
       
   }
}
int main() {
    struct node* tail = NULL;
    add(&tail, 0);
    add(&tail, 1);
    add(&tail, 2);
    add(&tail, 3);
    add(&tail, 4);
    add(&tail, 5);
    disp(tail);
    return 0;
}
Wednesday, November 24, 2021
Implementing circular list auto
Subscribe to:
Post Comments (Atom)
Priority queue deleting elements after ascending inputs Gaand Fadd
using namespace std; #include<iostream> #define N 5 class pq { public: int* arr; int front; int rear; pq() { ...
- 
//See sabse pehle ek khali node bana lena jiska prev and next null ho uske bad use return kar le fir saare operation perform kar lena //Tim...
 - 
#include<stdio.h> int main() { int temp; int arr[6] = {30, 45, 12, 51, 19, 8}; for(int i = 1; i<=5; i++) { ...
 - 
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node* next; }; void inElFr(struct node** head, int ...
 
No comments:
Post a Comment