My teacher ask to make a program that can:

Insert record in front
Insert record at the end
Insert in between
Search node record
Delete record in front
Delete record at the end
Delete record in between

Using Data structure Linked List type. But I'm really
confused about the codes and I can't go through. Please help
Thanks in advance. Also here is my unfinished code if
someone can make changes it will be more good.



My teacher ask to make a program that can: Insert record in front Insert record at the end Inse..

Answer / domz tubalado

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void dugay(){
int x;
printf("\nLoading...");
for(x=0;x<1000;x++)
{
delay(100);
if(x%100==0)
printf(".");
}
}

/*STRUCTURE*/
struct Node{
int ID;
char name[10];
char surname[10];
char course[7];

struct Node *Link;
};
typedef struct Node *NodePointer;

/*INSERT NODE IN FRONT*/

void InsertInFront(NodePointer *Head, int iID, char iname[10]){
NodePointer NewNode;
NewNode=(NodePointer)malloc(sizeof(struct Node));

NewNode->ID=iID;
strcpy(NewNode->name,iname);
printf("ID: ");
scanf("%d",&NewNode->ID);
printf("Name: ");
scanf("%s",&iname);
printf("\n");

NewNode->Link=*Head;
*Head=NewNode;
}

/*DELETE FRONT*/
void DeleteFront(NodePointer *Head){
NodePointer Temp;
if(*Head==NULL)
printf("Link list empty...Cannot delete");
else{
Temp=*Head;
*Head=(*Head)->Link;
free(Temp);
}
}

/*SEARCHING*/
NodePointer Searching(NodePointer *Head,int Key)
{
NodePointer Here;
Here=*Head;
while (Here!=NULL)
if((Here->ID)==Key)
return (Here);
else
Here=Here->Link;
return(NULL);
}

/*INSERT END*/
void InsertAtEnd(NodePointer *Head,int Number)
{
NodePointer NewNode,Temp;
NewNode=(NodePointer)malloc(sizeof(struct Node));
NewNode->ID=Number;
printf("\nNew Node:%d",NewNode->ID);
NewNode->Link=NULL;
if(Head==NULL)
*Head=NewNode;
else
{
Temp=*Head;
while(Temp->Link!=NULL)
Temp=Temp->Link;
Temp->Link=NewNode;
}
}

/*DELETE END */
void DeleteEnd(NodePointer *Head)
{
NodePointer Before,After;
if(*Head==NULL)
printf("\nLink List is empty!...Cannot Delete");
else
{
Before=NULL;
After=*Head;
while (After->Link!=NULL)
{
Before=After;
After=After->Link;
}
if ((*Head)->Link==NULL)
Head=NULL;
else
Before->Link=NULL;
free(After);
}
}

/*INSERT BETWEEN*/
void InsertInBetween(NodePointer Before, NodePointer After,
int Number)
{
NodePointer NewNode;
NewNode=(NodePointer)malloc(sizeof(struct Node));
NewNode->Link=NULL;
NewNode->ID=Number;
NewNode->Link=After;
Before->Link=NewNode;
}

/*DELETE BETWEEN*/
void DeleteInBetween(NodePointer Discard, NodePointer Before)
{
(Before)->Link=(Discard)->Link;
free(Discard);
}

/*DISPLAY NODES*/
void display(NodePointer *Head)
{
NodePointer current;
int row=3;
clrscr();
gotoxy(35,1);printf("LINK LIST");
printf("\n MENU");
printf("\n1.Insert record in front.");
printf("\n2.Insert record at the end.");
printf("\n3.Insert in between.");
printf("\n4.Search node record.");
printf("\n5.Delete record in front.");
printf("\n6.Delete record at the end.");
printf("\n7.Delete record in between.");
current=*Head;
gotoxy(52,2);printf("ID NUMBERS");
while(current!=NULL)
{
gotoxy(48,row);printf("Registered ID:%d",current->ID);
current=current->Link;
row++;
}
}

/*MAIN PROGRAM*/
void main(){
NodePointer Head=NULL,current;
NodePointer After,Before,Discard;
int x=0,node=0,data;
char y,select,zname;
do{
display(&Head);
gotoxy(1,10);
printf("\n\nSELECT MENU");
fflush(stdin);
scanf("%c",&select);
switch(select){
case '1':printf("No. of nodes to be inserted in front:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
InsertInFront(&Head,x,zname);
dugay();
display(&Head);
break;
case '2':printf("No of nodes to be inserted at end:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
InsertAtEnd(&Head,x);
dugay();
display(&Head);
break;
case '3':printf("Node Before:");
scanf("%d",&node);
Before=Searching(&Head,node);
printf("\nNode After:");
scanf("%d",&node);
After=Searching(&Head,node);
printf("\nNumber data to be inserted:");
scanf("%d",&data);
InsertInBetween(Before,After,data);
dugay();
display(&Head);
break;
case '4':printf("Input data to be searched:");
fflush(stdin);
scanf("%d",&node);
current=Searching(&Head,node);
printf("\nFound data:%d",current->ID);
dugay();
display(&Head);
break;
case '5':printf("No. of nodes to be deleted in front of
the head:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
DeleteFront(&Head);
dugay();
display(&Head);
break;
case '6':printf("No. of nodes to be deleted at the end:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
DeleteEnd(&Head);
dugay();
display(&Head);
break;
case '7':printf("Node no. before the node no. to be
deleted:");
printf("%d",&node);
Before=Searching(&Head,node);
printf("\nInput node to be deleted:");
scanf("%d",&node);
Discard=Searching(&Head,node);
DeleteInBetween(Discard,Before);
dugay();
display(&Head);
break;
default:
printf("Invalid Selection...");
}

gotoxy(28,20);printf("Want to continue?[y/n]:");
fflush(stdin);
scanf("%c",&y);
}while(toupper(y)!='N');
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

Distinguish between actual and formal arguments.

0 Answers  


What is a ternary operator in c?

0 Answers  


What are the different types of constants?

0 Answers  


What is the difference between struct and union in C?

1 Answers  


String concatenation

2 Answers  






C language questions for civil engineering

0 Answers   Tech Mahindra,


Hello friends !!! I’am Abhinav Ranjan Sinha College- L.K.C.T(Indore) I just want to express my personnal experience of getting placed at Consagous Technologies,to all freshers who are in search of the job. On 25th of Feb 2011 there was a campus drive of Consagous Technologies in our college.That was the second time any software company is coming to our college for batch, I was very excited. Firstly, they started with a seminar, a small introduction about the company.Then as the first round of the placement process, they conducted GD, in every group there was 20 students, and in the GD they just given the topics on the current affairs ,like- Global warming, Science is a curse or boon, girls are superior than boys?, etc. Then after half an hour the result of GD was announced , and fortunetly I was selected among the 150 other students. Then there was a written round, that was fully Technical , the question paper consists of total 50 questions out which 45 are optional and the rest of the 5 questions are not optional. Some of them which I remember are- 1.when we pass an argument to a function , then how it is being interpreted? Ans- Address of the first element of an array. 2.how the size of structure can be determined? 3.Complexity of binary search algorithm? Ans-0(logn) 4.what does the symbol << do in c++? 5.what does (.) dot operator do? 6.what is RTTI? 7.What is containership? And many more questions related to data structure on complexity, C program output, etc Then the result was declared on the next day, total 45 students are short leasted out of 150(approx) and the further rounds of Technical and HR are after two days. Then on 28th of Feb 2011 we are called for the next rounds, and that was the toughest time ever as my turn came almost at last , firstly my name was announced for the Technical round, there when I entered there are 3 persons inside the room who are taking the interview, as I entered they asked me to reduce the speed of the fan, I went to the switch board but the regulator was not working , then they told me to switch it off. Then , they offerd me to have a seat, there they asked me about- 1. what is your area of interest? 2. what is recursion? 3. write a program of factorial using recursion. 4. differentiate between My sql and Sql server. 5. they asked me questions related to my minor project. 6. what does get and post method do? 7. what is structure? 8. what is union? Out of which I have given answers of the many of them. Then I was called for the PI (personnmal interview) , I was very tired as it was 6:30 and I was waiting for my turn from 11’o clock onwards. But as I was very much exited , I just prayed to God and entered in the room, As I entered I saw two persons there inside the room I wished both of them, and they offerd me the chair, I replied with thank you sir thank you mam. Then the first question which I was asked there is- 1.Tell me something about yourself? Then, 2.they asked me of my strengths. 3.then suddenly they started asking aptitude questions, and the main thing is that they are not repeating the questions, you have to listen it very carefully. And the questions are like— Que- a man moves 50 km away from his house in the north direction, then he turns left and moves 50 km , and then again he turns left and moves 50 km, then at which place he is from his house and at what distance? Que- the ratio of the age of the two friends are in the ratio 6:5 then there ratio becomes 8:7 , so how many years they will it takes to gain this ratio? 4.where do you see yourself after 5 years? 5.tell me your 5 such skills which you can give to our organization. 6.what do you know about our company? They both are very calm and are of very good nature, and they are very supportive which helped me a lott . And just after half an hour the results had been declared and fortunetly with God’s Grace I got selected, that was the one of the very most imported and cherishable moment of my life. All The Best to all my dear friends , and I wish you for your bright future. And , at last but not the least, I would like to thanks to Consagous Technologies to give me such a big opportunity to prove myself in my life, thank you so much.

0 Answers  


prog for 1st five prime numbers in 2^x - 1

0 Answers  


write a program wch produces its own source code aas its output?

1 Answers   IonIdea,


Topics: Structures, Arrays, Searching and Sorting Assume there is a small mobile computer device including a hard disk and a slot for a memory card. The device shall be used to backup photos e.g. during holiday. Every time a memory card is connected all photos of the card are copied into a new folder automatically. And your task is to develop some basic controlling software to show, add, remove, search and sort the directories of photos. Step by Step Implementation 1.Define two symbolic constants, one to hold the total volume of the disk (e.g. VOLUME) and another one to hold the number of entries the files system of the device can handle (MAXFOLD). 2.Define a new structure data type named DATE to store a date consisting of year, month and day as unsigned values. 3.Define an other structure data type FOLDER to store the information of one folder of photos: &#9702;A title as character array of appropriate length &#9702;The location (event) the photos are taken as character array of appropriate length &#9702;The date of the day the photos are copied to the disk using the just defined data type DATE &#9702;The number of photos as natural number &#9702;And the size of the folder in MB as floating point value 4.Define the following global variables and initialise them: &#9702;disk as an array with MAXFOLD elements of data type FOLDER &#9702;folders as natural value to count the number of folders currently stored at the disk (valid elements in the array) TEST: Now you should be able to compile the code the first time without any warning or error. In the menu only "p" to print and "q" to quit will work!. 5.Now complete the functions given by their prototype: float freeSpace ();The function has to calculate the sum of the size component of all elements currently stored in the disk array. The function shall return the free space of the disk by the difference between the available total volume and the calculated sum. TEST: To test this function you only need to uncomment printing the "statusline" at the function actionmenu(). Compare the calculated value with a manual calculation of the example values given above. unsigned isBefore (DATE, DATE);The function checks if one date is before the other. There are 3 different possibilities which have to be handled. Imagine for example these 3 different combinations of values: &#9702;2010-01-01 : 2010-01-02 &#9702;2010-01-01 : 2010-02-01 &#9702;2010-01-01 : 2009-01-01 The function shall just return the result of the comparison. unsigned isEqual (DATE, DATE);The function checks if one date is equal to the other, all components have to be compared. The function shall just return the result of the comparison. int findByDate (DATE);As the array is should be kept in order (sorted by date) implement a binary search for a folder by its date here. You need only to adapt the binary search we used in the exercise. Use the 2 comparing functions above where appropriate. The function shall return the index of the element which was found or -1. TEST: Now you can try searching a folder by date via the "s" in the menu. Activate the corresponding part in the main function. int isSpaceLeft (FOLDER);This function compares the free space of the disk with the size of folder given with the parameter list. The function shall return 1 if there is enough space to add the folder, otherwise 0 (just the result of the comparison). void SortByDate ();This function shall implement the InsertionSort using the component date as key. Use the provided algorithm/souce code of the exercise as template. If you need a comparison between dates, use the function isBefore you have written again. void addFolder (FOLDER);The function has to check if the disk has additional capacities to add the new folder (number of folders and space left). If at least one of these conditions is false print an error message and return -1. Else there has to be added an other test to avoid 2 folder elements with the same date (use the findByDate function here. If there is no folder with the new date simply attach the new folder at the end of the array and call the sorting algorithm afterwards to keep the order in the array. TEST: Now you can try to add a folder via the "a" in the menu. Activate the corresponding part in the main function. void delDir (int);This function removes one element of the disk array. The input parameter contains the index of the element to delete. Deletion can simply be done by moving all elements at the right one to the left (overwriting the element to delete. The function may get a -1. This has to be checked first (certainly there is nothing to delete then!) Don't forget to decrement the counter of elements at the end. TEST: Now you can try to remove a folder by date via the "r" in the menu. Activate the corresponding part in the main function. unsigned findAllOfLocation(char[], FOLDER[]);This is an optional additional task: The function shall find all elements with the given value for the component location (first input parameter). The array elements which are found have to be added to the FOLDER array (second input parameter). As this parameter is an array we can use the result later in the main function. There kernel of function implements a modified linear search on the disk array (it does not stop if one element is found bat continues search until the location of all elements is checked). The finally function shall return the number of elements found in the disk array. TEST: Now you can try to add a folder by date via the "l" in the menu. Activate the corresponding part in the main function.

0 Answers   Siemens,


Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array.

0 Answers  


what is the difference between #include<> and #include”…”?

5 Answers  


Categories