C program – Sorting a Linked List

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#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;
		}
	}
}



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to create a linked list and display the elements in the list.
  2. C program to illustrate the operations of singly linked list
  3. C++ program – Implement the Queue ADT using a single linked list
  4. C++ program – Implement the double ended queue using a double linked list
  5. C++ programs – Implement the Stack ADT using a singly linked list

Leave a Comment

Previous post:

Next post: