From 095a997eb8f7583338636f8b69db4f727e83f049 Mon Sep 17 00:00:00 2001 From: NIRMAL M <86112673+NIRMAL1508@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:07:57 +0530 Subject: [PATCH] Create sort.c --- sort.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sort.c diff --git a/sort.c b/sort.c new file mode 100644 index 0000000000..e3190f0c84 --- /dev/null +++ b/sort.c @@ -0,0 +1,53 @@ +#include +#include +struct Node +{ + int data; + struct Node *next; +}*first=NULL,*second=NULL,*third=NULL; +void Display(struct Node *p) +{ + while(p!=NULL) + { + printf("%d ",p->data); + p=p->next; + } +} +void create(int A[],int n) +{ + int i; + struct Node *t,*last; + first=(struct Node *)malloc(sizeof(struct Node)); + first->data=A[0]; + first->next=NULL; + last=first; + + for(i=1;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; + } +} +int isSorted(struct Node *p) +{ + int x=-65536; + while(p!=NULL) + { + if(p->data < x) + return 0; + x=p->data; + p=p->next; + } + return 1; +} +int main() +{ + int A[]={10,60,20,30,40,50}; + create(A,5); + printf("%d\n",isSorted(first)); + Display(first); + return 0; +}