A program in ‘C’ language to display the names and seat numbers of all passengers of a bus in the form of a singly linked list. Use pointers. 10m Dec2007

By | June 10, 2015

Write a program in ‘C’ language to display the names and seat numbers of all passengers of a bus in the form of a singly linked list. Use pointers. 10m Dec2007

 

#include<stdio.h>
struct node
{
int seat;
char name[20];
struct node *next;
};
typedef struct node node; //with this Use “node” instead of “struct node”
node *root=NULL; //Global variable “root” pointer
node *create_node(int,char*); //Declaration
void insert(int,char*); //Declaration
void display_list(node *); //Declaration

void main()
{
clrscr();
display_list(root);
insert(1,”SAMEER”);
insert(2,”MAHESH”);
insert(3,”VARUN”);
insert(4,”RAHUL”);
display_list(root);
getch();
}

node *create_node(int x,char *nm)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->seat=x;
strcpy(temp->name,nm);
temp->next=NULL;
return temp;
}

void insert(int x,char *nm)
{
node *temp,*start;
start=root;
if(root==NULL)
{ root=create_node(x,nm);root->next=root;}
else
{
while(start->next!=root)
{
start=start->next;
} start->next=create_node(x,nm);
start->next->next=root;
}
}
void display_list(node *start)
{
if(start==NULL)
{ printf(“List is Empty!\n\n”); }
else
{
printf(“SEAT No.\tName of Passenger\n\n”);
while(start->next!=root)
{ printf(“%d\t\t”,start->seat);
printf(“%s\n”,start->name);
start=start->next;
}
printf(“%d\t\t”,start->seat);
printf(“%s\n”,start->name);
}
}

 

Code:

[codesyntax lang=”c”]

#include<stdio.h>
struct node
{
int seat;
char name[20];
struct node *next;
};
typedef struct node node; //with this Use “node” instead of “struct node”
node *root=NULL; //Global variable “root” pointer
node *create_node(int,char*); //Declaration
void insert(int,char*); //Declaration
void display_list(node *); //Declaration

void main()
{
clrscr();
display_list(root);
insert(1,”SAMEER”);
insert(2,”MAHESH”);
insert(3,”VARUN”);
insert(4,”RAHUL”);
display_list(root);
getch();
}

node *create_node(int x,char *nm)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->seat=x;
strcpy(temp->name,nm);
temp->next=NULL;
return temp;
}

void insert(int x,char *nm)
{
node *temp,*start;
start=root;
if(root==NULL)
{ root=create_node(x,nm);root->next=root;}
else
{
while(start->next!=root)
{
start=start->next;
} start->next=create_node(x,nm);
start->next->next=root;
}
}
void display_list(node *start)
{
if(start==NULL)
{ printf(“List is Empty!\n\n”); }
else
{
printf(“SEAT No.\tName of Passenger\n\n”);
while(start->next!=root)
{ printf(“%d\t\t”,start->seat);
printf(“%s\n”,start->name);
start=start->next;
}
printf(“%d\t\t”,start->seat);
printf(“%s\n”,start->name);
}

  • }
[/codesyntax]

Screen Shots:

C_program_Singly_link_Name

C_program_Singly_link_Name_Output

 

 

Explain any five functions of <stdlib.h> library. 10m Dec2007

Solved program can be found on this link http://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/

 

Write a program in ‘C’ that accepts a sentence ‘s’ and a word ‘w’ as input. Now, the program should print the starting position of right-most occurrence of ‘w’ in’s’. 10m Dec2007

 

Similar program can be found on this link http://cssimplified.com/c-programming/write-the-functions-to-perform-the-following-10m-dec2005-2