Sorted linked list C++ Chi Tiết

Kinh Nghiệm về Sorted linked list C++ 2021


Bann đang tìm kiếm từ khóa Sorted linked list C++ 2022-01-03 11:18:04 san sẻ Bí quyết về trong nội dung bài viết một cách Mới Nhất.







Create and Sort a Single Linked List – C Program




  • trang chủ > C Programs > C Linked List programs




  • « Previous

  • Next »



    Programs
  • C Linked List Programs

  • Create & Sort a single linked list

  • Create Odd & Even linked lists

  • Insert node in doubly linked list

  • Delete user specified node from circular linked list

  • Search an element in linked list

  • Print linked list in reverse order


Write a C program to create a single linked list and then sort that list using separate function (Use local pointer i.e. with return statement).

Solution:


Linked List:
Linked list is a linear data structure and each element containing the address of its successor. A linked list represents by a pointer to the first node of the linked list. The first node is called head.


In this example we developed two functions one for insertion of linked list and another is for sorting of elements.



Program


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
typedef struct node


int info;
struct node *next;
nodetype;
nodetype* insert(nodetype*);
void sort(nodetype*);
void main()


nodetype* left=NULL;
nodetype* right=NULL;
int ch,c;
printf(“Enter 1 for insert nEnter 2 for sort nEnter 3 for exit”);
do


printf(“nEnter choice: “);
scanf(“%d”,&ch);
switch(ch)


case 1:
right=insert(right);
if(left==NULL)


left=right;


break;
case 2:
sort(left);
case 3:
exit(1);
default:
printf(“invalid choice”);
break;


printf(“do you want to continuoe press 1: “);
scanf(“%d”,&c);
while(c==1);
getch();


nodetype* insert(nodetype *r)


i.nt n;
nodetype *p.;
p.=(nodetype*)malloc(sizeof(nodetype));
printf(“nEnter the number: “);
scanf(“%d”,&n);
if(p.!=NULL)


p.->info=n;
p.->next=NULL;
if(r==NULL)


r=p.;


else


r->next=p.;
r=p.;


return(r);


else


printf(“not enough memory”);


void sort(nodetype *l)


nodetype *t;
nodetype *s;
int x;
t=l;
while(t!=NULL)


s=t->next;
while(s!=NULL)


if(t->info>s->info)


x=t->info;
t->info=s->info;
s->info=x;


s=s->next;


t=t->next;


t=l;
while(t!=NULL)


printf(” %d “,t->info);
t=t->next;





Output:


sort single linked list



  • « Previous

  • Next »



Video tương quan













đoạn Clip Sorted linked list C++ ?


Một số hướng dẫn một cách rõ ràng hơn về đoạn Clip Sorted linked list C++ tiên tiến và phát triển nhất .


Chia SẻLink Tải Sorted linked list C++ miễn phí


Quý quý khách đang tìm một số trong những Chia SẻLink Download Sorted linked list C++ Free.

#Sorted #linked #list

Đăng nhận xét

Mới hơn Cũ hơn