Untitled

 avatar
unknown
plain_text
2 months ago
794 B
6
Indexable
#include <stdio.h>
#include <stdlib.h>

struct node {
   int data;
   struct node *next;
};

// display the list
void printList(struct node *head){
   struct node *p = head;
   printf("\n");

   //start from the beginning
   while(p != NULL) {
      printf("%d ",p->data);
      p = p->next;
   }
   printf("\n");
}

//insertion at the sorted position :  FILL HERE
void insertSorted(){

}

int main() {
    
    int a[] = {7,6,9,8,3,4,1,5,2};
    struct node *head = NULL;
    
    int len = sizeof(a)/sizeof(a[0]);


    //  print the array
    for(int i=0; i<len; i++)
        printf("%d ", a[i]);
    printf("\n");
    
    // insert in a sorted LL
    for(int i=0; i<len; i++) {
        insertSorted();               // FILL/ADJUST HERE
    }
    
    // print the LL
    printList(head);
}
Editor is loading...
Leave a Comment