473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

linked list with templates ...

Dear,

I wreated a small program that make a linked list of
factorials of numbers, I don't have expirience with
templates so I will bee thankfull if anybody can make
the same with templates(change my small program),
becouse I don't understand a templates.
Program is commpilled with Visual C++ 6.0.
(Escouse mee first version of program was
incorect becouse variable :"i" was seted to 1,
a true value is 0).

Thanks in advance !
Robert !
// fact.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
int fact(int);
int main(int argc, char* argv[])
{ struct number{
int broj;
struct number *next;
};
struct number *first, *temp;
int k, i;
char c;
first=(struct number *)malloc(sizeof(struct number));
first->broj=1;
temp=(struct number *)malloc(sizeof(struct number));
first->next=temp;
printf("\nEnter a number:");
scanf("%d",&k);
for(i=1;i<k;i++){
temp->next=(struct number *)malloc(sizeof(struct number));
// temp->broj=fact(k);
temp->broj=fact(i);
temp=temp->next;
temp->next=NULL;
// printf("\n%d!=%d",k,fact(k));
}
i=0; //HERE WAS A ERROR
temp=first;
while(temp->next){
printf("\n%d!=%d",i,temp->broj);
i++;
temp=temp->next;
}
c=getchar();
return 0;
}

int fact(int n){
if(n==1){
return 1;
}else{
return(n*fact(n-1));
}
}
Aug 18 '05 #1
7 2311
Robert Bralic wrote:
Dear,

I wreated a small program that make a linked list of
factorials of numbers, I don't have expirience with
templates so I will bee thankfull if anybody can make
the same with templates(change my small program),
becouse I don't understand a templates.
Program is commpilled with Visual C++ 6.0.
(Escouse mee first version of program was
incorect becouse variable :"i" was seted to 1,
a true value is 0).

Thanks in advance !
Robert !


How something like

#include <iostream>
#include <list>

using namespace std;

int fact(int n){
if(n==1){
return 1;
}else{
return(n*fact(n-1));
}
}

int main(){
int k;
list<int> l;

cout << "Enter a number: ";
cin >> k;

for(int i=1;i<k;i++)
l.push_back(fact(i));

int j=1;
for(list<int>::const_iterator i=l.begin();i!=l.end();i++,j++)
cout << j << "!=" << *i << "\n";

return 0;
}

Aug 18 '05 #2

"Azdo" <az************@yahoo.es> wrote in message
news:de**********@news.ya.com...
Robert Bralic wrote:
Dear,

I wreated a small program that make a linked list of
factorials of numbers, I don't have expirience with
templates so I will bee thankfull if anybody can make
the same with templates(change my small program),
becouse I don't understand a templates.
Program is commpilled with Visual C++ 6.0.
(Escouse mee first version of program was
incorect becouse variable :"i" was seted to 1,
a true value is 0).

Thanks in advance !
Robert !


How something like

#include <iostream>
#include <list>

using namespace std;

int fact(int n){
if(n==1){
return 1;
}else{
return(n*fact(n-1));
}
}

int main(){
int k;
list<int> l;

cout << "Enter a number: ";
cin >> k;

for(int i=1;i<k;i++)
l.push_back(fact(i));

int j=1;
for(list<int>::const_iterator i=l.begin();i!=l.end();i++,j++)
cout << j << "!=" << *i << "\n";

return 0;
}

----------------------------------------------------------------------------
--------------------------
When I try to compile with Visual C++ 6.0 it returns:

Deleting intermediate files and output files for project
'linked_factorial_with_templates - Win32 Debug'.
--------------------Configuration: linked_factorial_with_templates - Win32
Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
linked_factorial_with_templates.cpp
D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates.
cpp(29) : error C2371: 'i' : redefinition; different basic types

D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates.
cpp(25) : see declaration of 'i'
D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates.
cpp(29) : error C2677: binary '!=' : no global operator defined which takes
type 'class std::list<int,class std::allocator<int> >::iterator' (or there
is no acceptable conve
rsion)
D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates.
cpp(30) : error C2100: illegal indirection
Error executing cl.exe.

linked_factorial_with_templates.exe - 3 error(s), 0 warning(s)
----------------------------------------------------------------------------
---------------------------------------------


PROGRAM doesn't work ....???
Can you make him work ....??

Thanks in advance, Robert !


Aug 18 '05 #3

"Robert Bralic" <ro*********@yahoo.co.uk> wrote in message
news:de**********@ss405.t-com.hr...

"Azdo" <az************@yahoo.es> wrote in message
news:de**********@news.ya.com...
Robert Bralic wrote:
Dear,

I wreated a small program that make a linked list of
factorials of numbers, I don't have expirience with
templates so I will bee thankfull if anybody can make
the same with templates(change my small program),
becouse I don't understand a templates.
Program is commpilled with Visual C++ 6.0.
(Escouse mee first version of program was
incorect becouse variable :"i" was seted to 1,
a true value is 0).

Thanks in advance !
Robert !
How something like

#include <iostream>
#include <list>

using namespace std;

int fact(int n){
if(n==1){
return 1;
}else{
return(n*fact(n-1));
}
}

int main(){
int k;
list<int> l;

cout << "Enter a number: ";
cin >> k;

for(int i=1;i<k;i++)
l.push_back(fact(i));

int j=1;
for(list<int>::const_iterator i=l.begin();i!=l.end();i++,j++)
cout << j << "!=" << *i << "\n";

return 0;
}

--------------------------------------------------------------------------

-- --------------------------
When I try to compile with Visual C++ 6.0 it returns:

Deleting intermediate files and output files for project
'linked_factorial_with_templates - Win32 Debug'.
--------------------Configuration: linked_factorial_with_templates - Win32
Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
linked_factorial_with_templates.cpp
D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates. cpp(29) : error C2371: 'i' : redefinition; different basic types

D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates. cpp(25) : see declaration of 'i'
D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates. cpp(29) : error C2677: binary '!=' : no global operator defined which takes type 'class std::list<int,class std::allocator<int> >::iterator' (or there
is no acceptable conve
rsion)
D:\Robert\c\linked_factorial_with_templates\linked _factorial_with_templates. cpp(30) : error C2100: illegal indirection
Error executing cl.exe.

linked_factorial_with_templates.exe - 3 error(s), 0 warning(s)
-------------------------------------------------------------------------- -- ---------------------------------------------


PROGRAM doesn't work ....???
Can you make him work ....??

Thanks in advance, Robert !


And youst one thing :"IF YOU ARE FROM CROATIA" pleasae don't answer
mee.....!!!!
Aug 18 '05 #4
Robert Bralic wrote:


PROGRAM doesn't work ....???
Can you make him work ....??

Thanks in advance, Robert
!

Your compiler is too old and not compliant with today's standard. Try, for
example to use another compiler as the online test:

http://www.comeaucomputing.com/tryitout/

and you'll get no errors.

And youst one thing :"IF YOU ARE FROM CROATIA" pleasae don't answer
mee.....!!!!


I'm not Croatian, but I wonder what makes the difference. By the way, your
program is not a real C++ program, only C, it isn't portable because it
uses Windows headers and the idea of learning templates through factorials
is plain wrong because factorial is an algorithm only applicable to integer
data.

Goodbye, dear.
Aug 18 '05 #5

Azdo <az************@yahoo.es> wrote in message
news:de**********@news.ya.com...
Robert Bralic wrote:


PROGRAM doesn't work ....???
Can you make him work ....??

Thanks in advance, Robert !

Your compiler is too old and not compliant with today's standard. Try, for
example to use another compiler as the online test:

http://www.comeaucomputing.com/tryitout/

and you'll get no errors.

And youst one thing :"IF YOU ARE FROM CROATIA" pleasae don't answer
mee.....!!!!


I'm not Croatian, but I wonder what makes the difference. By the way, your
program is not a real C++ program, only C, it isn't portable because it
uses Windows headers and the idea of learning templates through factorials
is plain wrong because factorial is an algorithm only applicable to

integer data.

Goodbye, dear.


Maybe you're not a Croatian but your question is typicaly CROATIAN,
I am asking foer templates,and first idea that come on my mind is to
make a list of factorials(that's becouse for me seemed stupid to enter
a number from loops,and I like recoursive programing)....
Croatian always sends some kind of ansvers that lead discoution
far from original question....
Godbye, Robert !

There is devil behind your dor,
he's weeko of evil and a broken of the walls..
By:N.Cave

Aug 18 '05 #6
Bore Biko wrote:
Maybe you're not a Croatian but your question is typicaly CROATIAN,
I am asking foer templates,and first idea that come on my mind is to
make a list of factorials(that's becouse for me seemed stupid to enter
a number from loops,and I like recoursive programing)....
Croatian always sends some kind of ansvers that lead discoution
far from original question....
Godbye, Robert !

There is devil behind your dor,
he's weeko of evil and a broken of the walls..
By:N.Cave


Sorry, i didn't realize you was a troll before. Here are some other
(laughable) posts of Robert Bralic on the net:

"Does C++ really exists?"

http://www.usenet-archive.de/comp.la...ly_exists_.php

"Does Delphi really exists?"

http://www.talkaboutprogramming.com/...ges/57689.html

and more...

http://www.thetechtwo.com/detail-11478776.html

Seems we have a new philosopher on the group!
Aug 18 '05 #7

Azdo <az************@yahoo.es> wrote in message
news:de**********@news.ya.com...
Bore Biko wrote:
Maybe you're not a Croatian but your question is typicaly CROATIAN,
I am asking foer templates,and first idea that come on my mind is to
make a list of factorials(that's becouse for me seemed stupid to enter
a number from loops,and I like recoursive programing)....
Croatian always sends some kind of ansvers that lead discoution
far from original question....
Godbye, Robert !

There is devil behind your dor,
he's weeko of evil and a broken of the walls..
By:N.Cave
Sorry, i didn't realize you was a troll before. Here are some other
(laughable) posts of Robert Bralic on the net:

"Does C++ really exists?"

http://www.usenet-archive.de/comp.la...aly_exists_.ph
p
"Does Delphi really exists?"

http://www.talkaboutprogramming.com/...ages/57689.htm
l
and more...

http://www.thetechtwo.com/detail-11478776.html

Seems we have a new philosopher on the group!


This is typicaly CROATIAN post,
plase write the program with templates,
and don't dogin around!
This is not theme of my post.
I am learning the C++ for year
and I founded lots of things that
doesent work, so I am looking for
answers.
And when I asked a best C++
Croatian progremmers(I know them
from schul (fer in Zagreb)) they couldn't
make programs with many things that
are writen in C++ Book's.
After that I looked for 3 months
and asked anybody who knows
where I can find some small(1000-2000)
lines C++ program, and nobody answered
me, the posts where typicaly CROATIAN,
they mak fun with me,(AND NOBODY
COULDN'T TELL ME ANYTHYNG
ABOUT SMALL PROGRAM)...????
It is realy strange that you on the net
can find a G-bytes of program sources code:
Pascal, Fortran,LISP,Prolog,Gooedel,Java, C...
And nowhere C++ , or DELPHI.
I contacted a several of DELPHI programmers
and nobody told me anything about pointers,
I think that Delphi don't have a pointers:
first person told me that you joust declare
variable as pointer,
and other told me that pointer declaration
in Delphi goes with "^" sign.
From Computer language exam on faculty
profesor sad that pointer always must be operator...
(Let finish this discvoution or I will become CROAT...!!!
Robert !!!
Aug 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
2
by: Dave | last post by:
Hello all, I am creating a linked list implementation which will be used in a number of contexts. As a result, I am defining its value node as type (void *). I hope to pass something in to its...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
7
by: Indraseena | last post by:
Hi can anybody send me how to create a linked list program in C++. Basically I want to know how a node is handled in c++. I know this in c only. in c we create a structure and use that structure...
12
by: joshd | last post by:
Hello, Im sorry if this question has been asked before, but I did search before posting and couldnt find an answer to my problem. I have two classes each with corresponding linked lists, list1...
4
by: bejiz | last post by:
Hello, I have written a short program for practising linked lists. But there is surely something wrong for when I compile there is a unhandled exception and it does not print if I try to add more...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.