What is the advantage of doubly linked list over singly linked list?
It's not that one is better than the other. They are used in different circumstances. A linear linked list is used like an array, with the added benefits of random insertion/removal of elements, etc. A circular linked list is often used as a buffer where one portion of the program produces data and another consumes it, such as in communications.
What is hetrogenious linked list?
A heterogeneous linked list is a linked list where each node can store different types of data. This is different from a homogeneous linked list where all nodes store the same type of data. Heterogeneous linked lists can be useful for scenarios where you need to store multiple types of data in a single list.
What is a circular singly linked lists?
A circular singly linked list is a memory structure in programming that supports walking around the list in a circle. Such a list is almost always written in the following form:
class ListNode {
public ListNode nextNode;
public Object nodeData;
public void addNode(Object newData);
public void removeNode();
}
Note that I've just generalized the data structure, as each language will have a specific syntax that has to be followed.
The data is organized such that if you follow nextNode indefinitely, you will eventually circle all the way back to the original node you started at. This is the "circular" part of this list. Going in a circle is done like this:
while(ListNode node = CurrentNode.nextNode) {
/* Do some processing here */
}
Depending on the actual use case, care must be taken to ensure that you are not truly going around infinitely.
The "singly linked" part is identified by the single pointer (or reference, if you will) to the next available node, called nextNode. A "doubly linked" structure would also contain a "previousNode" pointer/reference.
void addNode(Object Data) {
ListNode temp = new ListNode();
temp.nextNode = CurrentNode.nextNode;
temp.Data = Data;
CurrentNode.nextNode = temp;
}
Inserting a new node can be done by inserting after the current entry. Inserting in place of the current entry would be slightly more complex, because you'd have to move the data pointers in the current node to the new node, then place the new data into the current node.
void removeNode() {
CurrentNode.nextNode = CurrentNode.nextNode.nextNode;
}
This code removes the node after the current entry. Again, to remove the current node instead of the one following, you would move the data from nextNode into the current node, then delete nextNode.
In a modern programming language, the old node will be garbage collected after a period of time, thus reclaiming the memory used. In other languages, you would need to "free" or "delete" the ListNode that was contained in CurrentNode.nextNode.
Student database using linked singly linked list?
/*Title : Creating Student Database Using Singly linked list */
#include<stdio.h>
#include<conio.h>
struct Student
{
int roll;
char name[30];
float marks;
struct Student *next; //Self referential pointer...
};
typedef struct Student Node;
void Linkfloat()
{
float a=0,*b; //To create link of float to some compiler ...
b=&a;
a=*b;
}
void Display(Node *head)
{
Node *p;
int i;
if(head==NULL)
{
printf("
There is no records in database.
");
}
else
{
p=head;
for(i=0;i<80;i++)
{
printf("-");
}
printf("
Updated Student Database
");
for(i=0;i<80;i++)
{
printf("-");
}
printf("
");
printf("Roll No. Name Marks
");
for(i=0;i<80;i++)
{
printf("-");
}
printf("
");
while(p!=NULL)
{
printf("%d %s %0.2f",p->roll,p->name,p->marks);
printf("
");
for(i=0;i<80;i++)
{
printf("-");
}
printf("
");
flushall();
p=p->next; //Go to next node...
}
}
}
void DReverse(Node * head)
{
Node *p;
int i;
if(head==NULL)
{
printf("
There is no records in database.
");
}
else
{
p=head;
if(p->next!=NULL)
{
DReverse(p->next); //Recursive call...
}
printf("%d %s %0.2f",p->roll,p->name,p->marks);
printf("
");
for(i=0;i<80;i++)
{
printf("-");
}
printf("
");
flushall();
printf("
");
}
}
Node* Create(Node *head)
{
int n,i;
Node *nn,*p;
printf("
How many Entries to Create Database???
");
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(head==NULL)
{
nn=(Node*)malloc(sizeof(Node)); //Creating first node...
printf("
Enter Roll No. , Name & Marks
");
scanf("%d",&(nn->roll));
flushall();
gets(nn->name);
scanf("%f",&(nn->marks));
nn->next=NULL; //Set next to NULL...
head=nn;
}
else
{
p=nn=head;
while(nn->next!=NULL)
{
nn=nn->next;
}
nn->next=(Node*)malloc(sizeof(Node)); //Creating further nodes...
nn=nn->next;
printf("
Enter Roll NO.,Name & Marks
");
scanf("%d",&(nn->roll));
flushall();
gets(nn->name);
scanf("%f",&(nn->marks));
nn->next=NULL;
nn=p;
}
}
return head;
}
Node* Insert(Node *head)
{
int ch,r;
char ans;
Node *p,*nn,*q;
do
{
printf("
Whwre do you want to enter new entry???
");
printf("
1.At the Begining
2.At the middle
3.At the end
");
printf("
Enter your choice:
");
scanf("%d",&ch);
switch(ch)
{
case 1:
/* Insert at Begining */
p=head;
nn=(Node*)malloc(sizeof(Node));
printf("
Enter Roll NO., Name & Marks
");
scanf("%d",&(nn->roll));
flushall();
gets(nn->name);
scanf("%f",&(nn->marks));
nn->next=NULL;
nn->next=p;
head=nn; //set first node as head...
printf("
Entry is Created successfully.
");
Display(head);
break;
case 2:
/* Insert at Middle */
if(head==NULL)
{
printf("
Yet database is not created.");
printf("
Database is empty.
");
printf("
First Create Database.
");
}
else
{
printf("
After which Roll NO. You want to insert new Data???
");
scanf("%d",&r);
p=head;
while(p->roll!=r && p->next!=NULL)
{
p=p->next; //Go upto that roll no....
}
if(p->roll!=r)
{
printf("
There is no such entry.
");
}
else
{
nn=(Node*)malloc(sizeof(Node));
printf("
Enter Roll NO.,Name & Marks
");
scanf("%d",&(nn->roll));
flushall();
gets(nn->name);
scanf("%f",&(nn->marks));
nn->next=NULL;
q=p->next;
p->next=nn;
nn->next=q;
printf("
Entry is Created successfully.
");
Display(head);
}
}
break;
case 3:
/* Insert at end */
if(head==NULL)
{
printf("
Yet database is not created.");
printf("
Database is empty.
");
printf("
First Create Database.
");
}
else
{
p=head;
nn=(Node*)malloc(sizeof(Node));
printf("
Enter Roll NO.,Name & Marks
");
scanf("%d",&(nn->roll));
flushall();
gets(nn->name);
scanf("%f",&(nn->marks));
nn->next=NULL;
while(p->next!=NULL)
{
p=p->next; //Go upto last node...
}
p->next=nn;
printf("
Entry is Created successfully.
");
Display(head);
}
break;
}
printf("
Do you want to Insert more data(Y/N)???");
flushall();
scanf("%c",&ans);
}while(ans=='y' ans=='Y');
return head;
}
Node* Delete(Node* head)
{
Node *p,*q,*r;
char ans;
int ch,n;
do{
printf("
Which Entry you want to Delete???
");
printf("
1.First
2.Middle
3.End
");
scanf("%d",&ch);
if(head==NULL)
{
printf("
Yet database is not created.");
printf("
Database is empty.
");
printf("
First Create Database.
");
}
else
{
switch(ch)
{
case 1:
/*Delete first node */
p=head;
head=head->next; //Set second node as head...
free(p);
printf("
First entry is deleted.
");
Display(head);
break;
case 2:
/*Delete middle Node*/
p=head;
printf("
Enter roll no. which you want to delete:
");
scanf("%d",&n);
while((p->next)->roll!=n && p->next->next!=NULL)
{
p=p->next; //Go upto -1 node which you want to delete...
}
if(p->next->next==NULL)
{
printf("
There is no such entry.
");
}
else
{
q=p->next;
r=q->next;
p->next=r;
free(q); //Delete that node...
printf("
Entry is deleted.
");
Display(head);
}
break;
case 3:
/* Delete last node */
p=head;
while(p->next->next!=NULL)
{
p=p->next; //Go upto -1 node which you want to delete...
}
q=p->next;
free(q); //Delete last node...
p->next=NULL;
printf("
Last entry is deleted.
");
Display(head);
break;
}
}
printf("
Do you want to delete more data(Y/N)???
");
flushall();
scanf("%c",&ans);
}while(ans=='y' ans=='Y');
return head;
}
Search(Node *head)
{
Node *p;
int r,cnt=0;
if(head==NULL)
{
printf("
Yet database is not created.");
printf("
Database is empty.
");
printf("
First Create Database.
");
}
else
{
p=head;
printf("
Enter roll no. which you want to Search:
");
scanf("%d",&r);
while(p->roll!=r && p->next!=NULL) //Search for roll no...
{
p=p->next;
cnt++;
}
if(p->roll!=r)
printf("
There is no such entry.
");
else
{
printf("
Roll NO. %d is at %d th Position.",r,(cnt+1));
printf("
Roll No. Name Marks
");
printf("%d %s %0.2f",p->roll,p->name,p->marks);
}
}
}
Modify(Node * head)
{
Node *p;
int r;
if(head==NULL)
{
printf("
Yet database is not created.");
printf("
Database is empty.
");
printf("
First Create Database.
");
}
else
{
p=head;
printf("
Enter the Roll no. whose data you want to modify:
");
scanf("%d",&r);
while(p->roll!=r && p->next!=NULL)
{
p=p->next;
}
if(p->roll!=r)
{
printf("
Thre is no such record in Database.
");
}
else
{
printf("
Entered roll no's Data is:
");
printf("Roll No. Name Marks
"); //Displaying Data who is going to modify....
printf("%d %s %f",p->roll,p->name,p->marks);
printf("
Enter New roll no ,New name & Marks for this entry:
");
scanf("%d",&p->roll);
flushall();
gets(p->name); //Enter new data...
scanf("%f",&(p->marks));
printf("
Entered New Data is:
");
printf("Roll No. Name Marks
");
printf("%d %s %f",p->roll,p->name,p->marks);
Display(head);
}
}
}
Count(Node *head)
{
Node *p;
int cnt=0;
if(head==NULL)
{
printf("
Yet database is not created.");
printf("
Database is empty.
");
printf("
First Create Database.
");
printf("
There are 0 records in Database.
");
}
else
{
p=head;
while(p->next!=NULL)
{
p=p->next;
cnt++; //Counting records...
}
printf("
There are %d records in Database.
",(cnt+1));
}
}
void main()
{
int ch,i;
char op;
Node *head;
head=NULL;
printf("
*----------Studednt Database-----------*
");
do
{
printf("
Menu
1.Create Database
2.Insert
3.Delete
4.Search
5.Modify
6.Display
7.Display Reverse
8.Count Records
9.Exit
");
printf("
Enter your choice
");
scanf("%d",&ch);
switch(ch)
{
case 1:
head=Create(head); //Call to Create...
break;
case 2:
head=Insert(head); //Call to Insert...
break;
case 3:
head=Delete(head); //Call to Delete...
break;
case 4:
Search(head); //Call to Search...
break;
case 5:
Modify(head); //Call to Modify...
break;
case 6:
Display(head); //Call to Display...
break;
case 7:
for(i=0;i<80;i++)
{
printf("-");
}
printf("
Updated Student Database
");
for(i=0;i<80;i++)
{
printf("-");
}
printf("
");
printf("Roll No. Name Marks
");
for(i=0;i<80;i++)
{
printf("-");
}
printf("
");
DReverse(head); //Call to displaying reversre...
break;
case 8:
Count(head); //Call to counting records...
break;
case 9:
exit(); //Exit...
default :
printf("
You entered wrong choice.
");
}
printf("
Do you want to Exit(Y/N)???
");
flushall();
scanf("%c",&op);
}while(op=='n' op=='N');
}
How do you implement a doubly linked list by using singly linked list?
Add another pointer to the nodes for the previous node:
struct node {
struct node *next;
struct node *previous;
void *data;
};
typedef struct node node;
Then change the logic for insertion and removal to make sure you set the previous pointer as well as the next one.
What is heterogeneous linked list?
Heterogeneous Linked List is a linked list data-structure that contains or is capable of storing data for different datatypes.
void pointer is basically used in these types of linked list as we are not sure of which type of data needs to be stored
Give 10 difference between dda and bresenham algorithm?
What is the difference between doubly linked list and circular linked list?
A doubly linked list is a linked list in which each node knows where both of its neighbors are.
A circular linked list is a linked list in which the "tail" of the list is linked to the "root". (Note that both the tail and root of the list are undefined/arbitrary in a circular linked list)
Doubly linked lists are actually not necessarily related to circular linked list (aside from both being based on a linked list structure). In fact, you can have a circular doubly linked list, where each node knows where both of its neighbors are andwhere the list wraps around to connect to itself.
What are examples of pattern recognition?
Examples of pattern recognition include detecting faces in images, identifying fraudulent behavior in financial transactions, and recognizing speech in audio recordings. These tasks involve recognizing consistent and repeating patterns within data to make accurate predictions or classifications.
What are the disadvantages of teaching on a class blackboard?
1. Eye to eye contact is lost while writing.
2. The written material cannot be stored and reused.
3. Advance preparation of material is not possible.
How do you find whether linked list is circular or not?
To determine if a linked list is circular, you can use the Floyd's cycle detection algorithm. This algorithm involves using two pointers moving at different speeds through the list, and if there is a cycle, the two pointers will eventually meet at the same node. If they don't meet and one of the pointers reaches the end of the list, then the list is not circular.
Main deffrent between c and cpp?
The main difference between c and c++ is the concept of 'Object Oriented Programming' (OOPS).
Thus c does not have the benefits of oops like:
1. abstraction
2. encapsulation
3. inheritance
4. polymorphism etc.
Common operation of singly linked list?
Common operations on a singly linked list include insertion (at the beginning, end, or specific position), deletion (from the beginning, end, or specific position), traversal (visiting each node in the list), searching (finding a specific value), and updating (modifying the value of a node).
Is a ruler a line or a line segment?
A ruler is a line segment because it ends at a one point when a line goes on forever.
What are conditional statements?
Conditional statements are used in programming to make decisions based on certain conditions. They allow the program to execute different code blocks depending on whether a condition is true or false. Common conditional statements include if, else, and else if.
Disadvantages of custom written software?
Some disadvantages of custom written software include higher development costs, longer implementation times, potential compatibility issues with other systems, and difficulties in scaling and maintaining the software as business needs evolve.
What is the difference between artificial neural network and hidden Markov model methods?
An artificial neural network is a structure which will attempt to find a relationship i.e. a function between the inputs, and the provided output(s), in order that when the net be provided with unseen inputs, and according with the recorded internal data (named "weights"), will try to find a correct answer for the new inputs. Hidden Markov models, are used for find the states for which a given stochastic process went through. The main difference could be this: In order to use a markov chain, the process must depend only in it´s last state. For use a neural network, you need a lot of past data. After training process, neural networks are capable of predicting next states of the system based only on the last state. In addition, given the ability to measure the prediction error (for example, after actual event, signal or state has happend and was compared to prediction), the neural network is capable of adapting itself and capture online changes in the undergoing process to improve the model of prediction and decrease the estimation error for the next states. Theoretically such approach can eliminate the need in initial training, as the network started from some random model will eventually adapt itself to the actual process it tries to estimate given this feedback error loop and will start to make correct estimations / predictions after a certain amount of steps. In such setup one can assume that neural network can be used when no past data is available at all. In this case neural network build the model of the ongoing process "from scratch" based on the observations in the "online" mode.
Now it is! This is how every word is "invented". Someone like you comes up with a new word to meet a new need, and eventually it finds its way to a dictionary. A dictionary is a follower, but you can be a leader. Good answer. Yes it is a word
How to get an output in inverted commas for example thank you in inverted commas in c progr amming?
To print "thank you" in inverted commas in C programming, you can use the following code:
#include <stdio.h>
int main() {
printf("\"thank you\"\n");
return 0;
}
This code will display the output as: "thank you"
How do you find what version of Microsoft Excel you have?
Go to the Help menu and look at the About option which will tell you. The version of Excel you have is linked to the version of Office you have. If you know what version of Office you have, then you know what version of Excel you have.
How do I calculate the position of 12 squares aligned around the edges of a do-decagon?
To calculate the position of the 12 squares aligned around the edges of a perfect dodecagon, you can use the following steps:
Calculate the radius of the dodecagon:
The edges of the dodecagon are 576 units long, and the dodecagon is a regular polygon, so the radius can be calculated as:
Radius = (Edge Length) / (2 × tan(π/12)) = 576 / (2 × tan(π/12)) ≈ 500.00 units
Calculate the position of the centers of the squares:
The squares are 576 × 576 units, so their centers will be 288 units away from the edge of the dodecagon.
The centers of the squares will be evenly spaced around the dodecagon, with an angular separation of 30 degrees (360 degrees / 12 squares).
The coordinates of the centers of the squares can be calculated using the following formulas:
x = (Radius + 288) × cos(θ)
y = (Radius + 288) × sin(θ)
Where θ is the angle of the square, starting from the positive x-axis and increasing counterclockwise.
Applying these formulas, the coordinates of the centers of the 12 squares are:
(681.40, 1801.21)
(1365.45, 1117.77)
(1365.45, -1117.77)
(681.40, -1801.21)
(-681.40, -1801.21)
(-1365.45, -1117.77)
(-1365.45, 1117.77)
(-681.40, 1801.21)
(0.00, 2000.00)
(1000.00, 1732.05)
(1000.00, -1732.05)
(0.00, -2000.00)
Okay, let's solve this step-by-step:
We have a regular dodecagon with edge length of 576 units.
The dodecagon is centered at (0, 0).
You want to place 12 squares of size 576 x 576 units around the edges of the dodecagon.
The squares should be rotated 30 degrees more than the previous one.
To calculate the position of the centers of the 12 squares:
The angle between each square is 360/12 = 30 degrees.
The radius of the dodecagon is 576 / (2 * tan(π/12)) = 500 units.
The center of the first square is at:
x = 500 * cos(0) = 500
y = 500 * sin(0) = 0
The center of the second square is at:
x = 500 * cos(30 * π/180) = 433.01
y = 500 * sin(30 * π/180) = 250.00
Continuing this pattern, the coordinates of the 12 square centers are:
| Square | X | Y |
| --- | --- | --- |
| 1 | 500.00 | 0.00 |
| 2 | 433.01 | 250.00 |
| 3 | 250.00 | 433.01 |
| 4 | 0.00 | 500.00 |
| 5 | -250.00 | 433.01 |
| 6 | -433.01 | 250.00 |
| 7 | -500.00 | 0.00 |
| 8 | -433.01 | -250.00 |
| 9 | -250.00 | -433.01 |
| 10 | 0.00 | -500.00 |
| 11 | 250.00 | -433.01 |
| 12 | 433.01 | -355.o1
The coordinates are rounded to two decimal places, as requested.
What are the advantages of second generation programming language?
Easier to learn: Second-generation programming languages are easier to learn than first-generation languages. They are closer to human language and are more intuitive