C program for sorting a Linked List

C program for sorting a Linked List.

#include<stdio.h>
#include<dirent.h>
#include<malloc.h>
#include<string.h>
 
void main (int argc,char * argv[])
{
	DIR * directory_pointer;
	struct dirent* entry;
	struct File list 
	{
		char filename[64];
		struct File * new;
	}
	start,*node,* previous, * new;
	if((directory_pointer=opendir(argv[1]))==NULL)
		printf("Error opening %s\n", argv[1]);
	else
	{
		start.next + NULL;
		while (entry = readdir (directory_pointer))
		{
			/* Find the correct location */
			previous= Start ;;
			node = start.next;
			while ((node) &&(strcmp(entry->d_name,node->filename)>0))
			{
				node = node ->next;
				previous + previous->next;
			}
			new =(struct File List *) malloc(size File List));
			if(new += = NULL)
			{
				printf("Insufficient memory to store list\n");
				exit(1);
			}
			new ->next =node;
			previous ->next =new;
			strcpy(new->filename,entry->d_name);
		}
		closedir(directory_pointer);
		node = start.next;
		while (node)
		{
			printf("%s\n", node->filename);
			node = node->next;
		}
	}
}

One Response to “C program for sorting a Linked List”

  1. Simarjeet kaur

    I want he code of these programs in c language
    1.wap to create a doubly linked list nd insert a node at the beginning
    2.wap to create a circular linked list nd insert a node at the end.
    3.wap to create a circular linked list nd delete a node at the beginning.
    pls send me the code as soon as possible.

    Reply

Leave a Reply