Professional Documents
Culture Documents
(EC-594B)
A. K. Siromoni
Lecture Objective 3 : Justify the use of different types of Link List in different
situation
Last Lecture
• We have understood Algorithmic Decomposition
#include<stdio.h>
•Definition of showdata
#include<stdio.h>
struct link { int data;
struct link *next; } ;
main() { struct link *head , *node;
void showdata(struct link * node){ head = createnode();
struct link * head = node; putdata(head);
do{ node=head;
printf (“%d \n”, node->data); while(getans()) {
node = node->next;}while (node!=head); } node->next = createnode();
node=node->next;
int getans(){int ans; putdata(node);
printf(“put 0 for stop , non zero to }
continue”); node->next=head;
scanf(“%d”, &ans); return ans;} showdata(head);
showdata(node); }
void putdata(struct link * node){ int data;
scanf(“%d”, &data);
node->data = data;
node->next = NULL; }
1. Link { Data; Next Link Address, Previous Link Address} //Data type
2. Link_address Head, Node, Prev = NULL // Start Storage
3. Head =createnode()
4. Putdata(Head, Prev)
5. Node=Head
6. Node_next = createnode()
7. Prev = Node
8. Node= Node_next
9. Putdata(Node, Prev)
10.Ask user if answer = yes coninue, go to 6 //End Storage
11.Showdata(Head) // Related Operation
12.Showdata(Node) // Related Operation
Implementation through Algorithmic Decomposition contd.
Partial implementation in C language
/*Doubly Link List in C Language */
#include<stdio.h>
•Definition of putdata
#include<stdio.h>
struct link { int data;
struct link *next; struct link * createnode() {
struct link * previous;} ; struct link * node;
node = (struct link *) malloc (sizeof(struct link));
void showdata1(struct link * node){ return node; }
while (node != NULL){
printf (“%d \n”, node->data);
node = node->next; } }
main() { struct link *head , *node, *prev=NULL;
void showdata2(struct link * node){ head = createnode();
while (node != NULL){ putdata(head, prev);
printf (“%d \n”, node->data); node=head;
node = node->previous; } } while(getans()) {
node->next = createnode();
prev=node;
int getans(){int ans; node=node->next;
printf(“put 0 for stop , non zero to continue”); putdata(node, prev);
scanf(“%d”, &ans); return ans;} }
showdata1(head);
void putdata(struct link * node, struct link *prev){ showdata2(node)
int data; }
scanf(“%d”, &data);
node->data = data;
node->next = NULL;
node ->previous = prev; }
Assignment 2
1. Josephus Problem
Given a group of n men arranged in a circle under the edict that every mth man
will be executed going around the circle until only one remains, find the
position in which you should stand in order to be the last survivor .
( m and n will be given by user )
3. Polynomial
Given two polynomial numbers represented by linked list. Write a function that add
these lists means add the coefficients who have same variable powers.
3. https://en.wikipedia.org/wiki/Josephus_problem
5. https://www.youtube.com/watch?v=3tDBX4-0Jt4